Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
U
uniset2
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
UniSet project repositories
uniset2
Commits
a8e58a09
Commit
a8e58a09
authored
May 17, 2021
by
Pavel Vainerman
Committed by
Pavel Vainerman
Jun 30, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[unet-multicast]: added "exchange test"
parent
20e10665
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
58 additions
and
10 deletions
+58
-10
MulticastTransport.cc
extensions/UNetUDP/MulticastTransport.cc
+15
-4
MulticastTransport.h
extensions/UNetUDP/MulticastTransport.h
+4
-2
UDPTransport.cc
extensions/UNetUDP/UDPTransport.cc
+1
-1
UDPTransport.h
extensions/UNetUDP/UDPTransport.h
+1
-1
test_unetmulticast.cc
extensions/UNetUDP/tests/test_unetmulticast.cc
+35
-0
unetudp-test-configure.xml
extensions/UNetUDP/tests/unetudp-test-configure.xml
+2
-2
No files found.
extensions/UNetUDP/MulticastTransport.cc
View file @
a8e58a09
...
...
@@ -246,6 +246,8 @@ std::unique_ptr<MulticastSendTransport> MulticastSendTransport::createFromXml( U
if
(
!
it
.
find
(
"send"
)
)
throw
SystemError
(
"(MulticastSendTransport): not found <send> node"
);
int
ttl
=
it
.
getPIntProp
(
"ttl"
,
1
);
if
(
!
it
.
goChildren
()
)
throw
SystemError
(
"(MulticastSendTransport): empty <send> groups"
);
...
...
@@ -271,12 +273,13 @@ std::unique_ptr<MulticastSendTransport> MulticastSendTransport::createFromXml( U
groups
.
push_back
(
a
);
}
return
unisetstd
::
make_unique
<
MulticastSendTransport
>
(
h
,
p
,
std
::
move
(
groups
));
return
unisetstd
::
make_unique
<
MulticastSendTransport
>
(
h
,
p
,
std
::
move
(
groups
)
,
ttl
);
}
// -------------------------------------------------------------------------
MulticastSendTransport
::
MulticastSendTransport
(
const
std
::
string
&
_host
,
int
_port
,
const
std
::
vector
<
Poco
::
Net
::
IPAddress
>&
_sendGroups
)
:
MulticastSendTransport
::
MulticastSendTransport
(
const
std
::
string
&
_host
,
int
_port
,
const
std
::
vector
<
Poco
::
Net
::
IPAddress
>&
_sendGroups
,
int
_ttl
)
:
saddr
(
_host
,
_port
),
groups
(
_sendGroups
)
groups
(
_sendGroups
),
ttl
(
_ttl
)
{
}
...
...
@@ -306,6 +309,13 @@ bool MulticastSendTransport::isConnected() const
return
udp
!=
nullptr
;
}
// -------------------------------------------------------------------------
void
MulticastSendTransport
::
setTimeToLive
(
int
_ttl
)
{
ttl
=
ttl
;
if
(
udp
)
udp
->
setTimeToLive
(
_ttl
);
}
// -------------------------------------------------------------------------
bool
MulticastSendTransport
::
createConnection
(
bool
throwEx
,
timeout_t
sendTimeout
)
{
try
...
...
@@ -316,6 +326,7 @@ bool MulticastSendTransport::createConnection( bool throwEx, timeout_t sendTimeo
udp
->
joinGroup
(
s
);
udp
->
setSendTimeout
(
UniSetTimer
::
millisecToPoco
(
sendTimeout
)
);
udp
->
setTimeToLive
(
ttl
);
}
catch
(
const
std
::
exception
&
e
)
{
...
...
@@ -349,7 +360,7 @@ bool MulticastSendTransport::isReadyForSend( timeout_t tout )
return
udp
&&
udp
->
poll
(
UniSetTimer
::
millisecToPoco
(
tout
),
Poco
::
Net
::
Socket
::
SELECT_WRITE
);
}
// -------------------------------------------------------------------------
ssize_t
MulticastSendTransport
::
send
(
void
*
buf
,
size_t
sz
)
ssize_t
MulticastSendTransport
::
send
(
const
void
*
buf
,
size_t
sz
)
{
return
udp
->
sendTo
(
buf
,
sz
,
saddr
);
}
...
...
extensions/UNetUDP/MulticastTransport.h
View file @
a8e58a09
...
...
@@ -60,7 +60,7 @@ namespace uniset
static
std
::
unique_ptr
<
MulticastSendTransport
>
createFromXml
(
UniXML
::
iterator
it
,
const
std
::
string
&
defaultIP
,
int
numChan
);
MulticastSendTransport
(
const
std
::
string
&
host
,
int
port
,
const
std
::
vector
<
Poco
::
Net
::
IPAddress
>&
sendGroups
);
MulticastSendTransport
(
const
std
::
string
&
host
,
int
port
,
const
std
::
vector
<
Poco
::
Net
::
IPAddress
>&
sendGroups
,
int
ttl
=
1
);
virtual
~
MulticastSendTransport
();
virtual
bool
isConnected
()
const
override
;
...
...
@@ -71,13 +71,15 @@ namespace uniset
// write
virtual
bool
isReadyForSend
(
timeout_t
tout
)
override
;
virtual
ssize_t
send
(
const
void
*
buf
,
size_t
sz
)
override
;
v
irtual
ssize_t
send
(
void
*
buf
,
size_t
sz
)
override
;
v
oid
setTimeToLive
(
int
ttl
)
;
protected
:
std
::
unique_ptr
<
MulticastSocketU
>
udp
;
const
Poco
::
Net
::
SocketAddress
saddr
;
const
std
::
vector
<
Poco
::
Net
::
IPAddress
>
groups
;
int
ttl
;
// ttl for packets
};
}
// end of uniset namespace
...
...
extensions/UNetUDP/UDPTransport.cc
View file @
a8e58a09
...
...
@@ -213,7 +213,7 @@ bool UDPSendTransport::isReadyForSend( timeout_t tout )
return
udp
&&
udp
->
poll
(
UniSetTimer
::
millisecToPoco
(
tout
),
Poco
::
Net
::
Socket
::
SELECT_WRITE
);
}
// -------------------------------------------------------------------------
ssize_t
UDPSendTransport
::
send
(
void
*
buf
,
size_t
sz
)
ssize_t
UDPSendTransport
::
send
(
const
void
*
buf
,
size_t
sz
)
{
return
udp
->
sendTo
(
buf
,
sz
,
saddr
);
}
...
...
extensions/UNetUDP/UDPTransport.h
View file @
a8e58a09
...
...
@@ -68,7 +68,7 @@ namespace uniset
// write
virtual
bool
isReadyForSend
(
timeout_t
tout
)
override
;
virtual
ssize_t
send
(
void
*
buf
,
size_t
sz
)
override
;
virtual
ssize_t
send
(
const
void
*
buf
,
size_t
sz
)
override
;
protected
:
std
::
unique_ptr
<
UDPSocketU
>
udp
;
...
...
extensions/UNetUDP/tests/test_unetmulticast.cc
View file @
a8e58a09
...
...
@@ -34,6 +34,41 @@ TEST_CASE("[UNetUDP]: multicast setup", "[unetudp][multicast][config]")
auto
t2
=
MulticastSendTransport
::
createFromXml
(
it
,
"192.168.1.1"
,
2
);
REQUIRE
(
t2
->
toString
()
==
"127.0.1.1:2999"
);
}
// -----------------------------------------------------------------------------
TEST_CASE
(
"[UNetUDP]: multicast receive"
,
"[unetudp][multicast][exchange]"
)
{
UniXML
xml
(
"unetudp-test-configure.xml"
);
UniXML
::
iterator
it
=
xml
.
findNode
(
xml
.
getFirstNode
(),
"nodes"
);
REQUIRE
(
it
.
getCurrent
()
);
REQUIRE
(
it
.
goChildren
()
);
REQUIRE
(
it
.
findName
(
"item"
,
"localhost"
,
false
)
);
REQUIRE
(
it
.
getName
()
==
"item"
);
REQUIRE
(
it
.
getProp
(
"name"
)
==
"localhost"
);
auto
t1
=
MulticastReceiveTransport
::
createFromXml
(
it
,
"127.0.0.1"
,
0
);
REQUIRE
(
t1
->
toString
()
==
"127.0.0.1:3000"
);
REQUIRE
(
t1
->
createConnection
(
false
,
5000
,
true
)
);
auto
t2
=
MulticastSendTransport
::
createFromXml
(
it
,
"127.0.0.1"
,
0
);
REQUIRE
(
t2
->
toString
()
==
"127.0.0.1:3000"
);
REQUIRE
(
t2
->
createConnection
(
false
,
5000
)
);
string
msg
=
"hello world"
;
REQUIRE
(
t2
->
send
(
msg
.
data
(),
msg
.
size
())
==
msg
.
size
()
);
unsigned
char
buf
[
64
];
REQUIRE
(
t1
->
receive
(
&
buf
,
sizeof
(
buf
))
==
msg
.
size
()
);
REQUIRE
(
string
((
const
char
*
)
buf
)
==
msg
);
REQUIRE
(
t1
->
receive
(
&
buf
,
sizeof
(
buf
))
==
-
1
);
msg
=
"hello world, again"
;
REQUIRE
(
t2
->
send
(
msg
.
data
(),
msg
.
size
())
==
msg
.
size
()
);
memset
(
buf
,
0
,
sizeof
(
buf
));
REQUIRE
(
t1
->
receive
(
&
buf
,
sizeof
(
buf
))
==
msg
.
size
()
);
REQUIRE
(
string
((
const
char
*
)
buf
)
==
msg
);
}
// -----------------------------------------------------------------------------
extensions/UNetUDP/tests/unetudp-test-configure.xml
View file @
a8e58a09
...
...
@@ -36,10 +36,10 @@
<item
id=
"3000"
ip=
"127.0.0.1"
name=
"localhost"
textname=
"Локальный узел"
unet_ignore=
"0"
unet_port=
"3000"
unet_multicast_ip2=
"127.0.1.1"
unet_multicast_port2=
"2999"
>
<multicast>
<receive>
<group
addr=
"2
24.0.0.1"
addr2=
"224.0.1
.1"
/>
<group
addr=
"2
39.255.1.1"
addr2=
"239.255.2
.1"
/>
</receive>
<send>
<group
addr=
"2
24.0.0.1"
addr2=
"224.0.1
.1"
/>
<group
addr=
"2
39.255.1.1"
addr2=
"239.255.2
.1"
/>
</send>
</multicast>
</item>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment