Commit 59a2d0c8 authored by Pavel Vainerman's avatar Pavel Vainerman Committed by Pavel Vainerman

[unet-multicast]: supported text name for iface and sender_ip

parent e98b11e7
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
<!-- Общие(стартовые) параметры по UniSet --> <!-- Общие(стартовые) параметры по UniSet -->
<UniSet> <UniSet>
<NameService host="localhost" port="2809"/> <NameService host="localhost" port="2809"/>
<LocalNode name="LocalhostNode"/> <LocalNode name="localhost"/>
<RootSection name="UNISET_PLC"/> <RootSection name="UNISET_PLC"/>
<CountOfNet name="1"/> <CountOfNet name="1"/>
<RepeatCount name="3"/> <RepeatCount name="3"/>
...@@ -81,7 +81,7 @@ ...@@ -81,7 +81,7 @@
<item filter="a2" fuse_id="AlarmFuse2_AS" fuse_value="2" id="2" size="30"/> <item filter="a2" fuse_id="AlarmFuse2_AS" fuse_value="2" id="2" size="30"/>
</History> </History>
<ReservList> <ReservList>
<item node="LocalhostNode" name="ReservSharedMemory"/> <item node="localhost" name="ReservSharedMemory"/>
</ReservList> </ReservList>
</SharedMemory> </SharedMemory>
<UniExchange name="UniExchange"> <UniExchange name="UniExchange">
...@@ -197,8 +197,8 @@ ...@@ -197,8 +197,8 @@
</RRDServer1> </RRDServer1>
<specnet unet_broadcast_ip="192.168.1.255" unet_broadcast_ip2="192.168.122.255"> <specnet unet_broadcast_ip="192.168.1.255" unet_broadcast_ip2="192.168.122.255">
<item id="3100" ip="127.0.0.1" name="LocalhostNode" textname="Локальный узел" unet_ignore="0" unet_port="2048"/> <item id="3100" ip="127.0.0.1" name="localhost" textname="Локальный узел" unet_ignore="0" unet_port="2048"/>
<item id="3101" ip="127.0.0.1" name="LocalhostNode" textname="Локальный узел" unet_ignore="0" unet_port="2048"/> <item id="3101" ip="127.0.0.1" name="localhost" textname="Локальный узел" unet_ignore="0" unet_port="2048"/>
</specnet> </specnet>
<GroupAnalogSensors name="TestGroup" ok_c="D106_S"/> <GroupAnalogSensors name="TestGroup" ok_c="D106_S"/>
...@@ -214,31 +214,42 @@ ...@@ -214,31 +214,42 @@
priority - приоритет сообщения об изменении данного датчика priority - приоритет сообщения об изменении данного датчика
textname - текстовое имя датчика textname - текстовое имя датчика
--> -->
<nodes port="2809" unet_broadcast_ip="127.255.255.255" unet_broadcast_ip2="192.168.56.255" unet_transport="multicast" unet_multicast_ip="0.0.0.0"> <nodes port="2809" unet_broadcast_ip="127.255.255.255" unet_broadcast_ip2="192.168.56.255">
<item id="3000" dbserver="DBServer1" infserver="InfoServer" ip="127.0.0.1" name="LocalhostNode" textname="Локальный узел" unet_ignore="0" unet_port="2048"> <item id="3000" dbserver="DBServer1" infserver="InfoServer" ip="127.0.0.1" name="localhost" textname="Локальный узел"
unet_ignore="0" unet_port="2048"
unet_multicast_ip="226.0.31.1"
unet_multicast_iface="lo"
unet_multicast_port="3110"
unet_multicast_sender_ip="192.168.0.4"
unet_multicast_ip2="227.0.31.1"
unet_multicast_port2="3120"
unet_multicast_sender_ip2="192.168.0.47">
<iocards> <iocards>
<item card="1" name="DI32"/> <item card="1" name="DI32"/>
<item card="2" name="DO32"/> <item card="2" name="DO32"/>
<item baddr="0x110" card="3" dev="/dev/null" name="UNIO48" subdev1="TBI24_0" subdev2="TBI16_8"/> <item baddr="0x110" card="3" dev="/dev/null" name="UNIO48" subdev1="TBI24_0" subdev2="TBI16_8"/>
</iocards> </iocards>
<multicast>
<receive>
<group addr="224.0.0.1"/>
</receive>
<send>
<group addr="224.0.0.1"/>
</send>
</multicast>
</item> </item>
<item id="3001" infserver="InfoServer" ip="127.0.0.1" name="LocalhostNode1" textname="Локальный узел" unet_ignore="0" unet_port="2049"/> <item id="3001" infserver="InfoServer" ip="127.0.0.1" name="LocalhostNode1" textname="Локальный узел"
<item id="3002" ip="192.168.56.10" name="Node1" textname="Node1" unet_ignore="0" unet_port="3001" unet_respond_id="Input1_S" unet_respond_invert="1"/> unet_port="2049"
<item id="3003" ip="192.168.56.11" name="Node2" textname="Node2" unet_ignore="0" unet_port="3002"/> unet_multicast_ip="226.0.31.2"
<item id="3004" ip="192.168.56.12" name="Node3" textname="Node3"/> unet_multicast_iface="lo"
<item id="3005" ip="192.168.56.13" name="Node4" textname="Node4"/> unet_multicast_port="3112"
<item id="3006" ip="192.168.56.14" name="Node5" textname="Node5"/> unet_multicast_sender_ip="192.168.3.75"
<item id="3007" ip="192.168.56.15" name="Node6" textname="Node6"/>
<item id="3008" ip="192.168.56.16" name="Node7" textname="Node7"/> unet_multicast_ip2="227.0.31.2"
<item id="3009" ip="192.168.56.17" name="Node8" textname="Node8"/> unet_multicast_port2="3122"
unet_multicast_sender_ip2="192.168.0.48"/>
<item id="3002" ip="192.168.56.10" name="Node1" textname="Node1" unet_ignore="1" unet_port="3001" unet_respond_id="Input1_S" unet_respond_invert="1"/>
<item id="3003" ip="192.168.56.11" name="Node2" textname="Node2" unet_ignore="1" unet_port="3002"/>
<item id="3004" ip="192.168.56.12" name="Node3" textname="Node3" unet_ignore="1"/>
<item id="3005" ip="192.168.56.13" name="Node4" textname="Node4" unet_ignore="1"/>
<item id="3006" ip="192.168.56.14" name="Node5" textname="Node5" unet_ignore="1"/>
<item id="3007" ip="192.168.56.15" name="Node6" textname="Node6" unet_ignore="1"/>
<item id="3008" ip="192.168.56.16" name="Node7" textname="Node7" unet_ignore="1"/>
<item id="3009" ip="192.168.56.17" name="Node8" textname="Node8" unet_ignore="1"/>
</nodes> </nodes>
<!-- ************************ Датчики ********************** --> <!-- ************************ Датчики ********************** -->
<sensors name="Sensors"> <sensors name="Sensors">
......
...@@ -109,8 +109,44 @@ MulticastReceiveTransport::MulticastReceiveTransport( const std::string& _bind, ...@@ -109,8 +109,44 @@ MulticastReceiveTransport::MulticastReceiveTransport( const std::string& _bind,
groups(_joinGroups), groups(_joinGroups),
ifaceaddr(_iface) ifaceaddr(_iface)
{ {
if( !ifaceaddr.empty() )
{
try
{
Poco::Net::NetworkInterface iface;
try
{
iface = Poco::Net::NetworkInterface::forName(ifaceaddr);
}
catch(...) {}
if( iface.name().empty() )
iface = Poco::Net::NetworkInterface::forAddress(Poco::Net::IPAddress(ifaceaddr));
if( iface.name().empty() )
{
ostringstream err;
err << "(MulticastReceiveTransport): Not found interface for '" << ifaceaddr << "'";
throw uniset::SystemError(err.str());
}
}
catch( const Poco::Net::InterfaceNotFoundException& ex )
{
ostringstream err;
err << "(MulticastReceiveTransport): Not found interface for '" << ifaceaddr << "'";
throw uniset::SystemError(err.str());
}
catch( const std::exception& ex )
{
ostringstream err;
err << "(MulticastReceiveTransport): Not found interface for '" << ifaceaddr
<< "' err: " << ex.what();
throw uniset::SystemError(err.str());
}
}
} }
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
MulticastReceiveTransport::~MulticastReceiveTransport() MulticastReceiveTransport::~MulticastReceiveTransport()
{ {
...@@ -167,10 +203,32 @@ bool MulticastReceiveTransport::createConnection( bool throwEx, timeout_t readTi ...@@ -167,10 +203,32 @@ bool MulticastReceiveTransport::createConnection( bool throwEx, timeout_t readTi
try try
{ {
Poco::Net::NetworkInterface iface; Poco::Net::NetworkInterface iface;
iface.addAddress(Poco::Net::IPAddress()); // INADDR_ANY
if( !ifaceaddr.empty() ) if( ifaceaddr.empty() )
iface = Poco::Net::NetworkInterface::forAddress(Poco::Net::IPAddress(ifaceaddr)); iface.addAddress(Poco::Net::IPAddress()); // INADDR_ANY
else
{
try
{
iface = Poco::Net::NetworkInterface::forName(ifaceaddr);
}
catch(...) {}
if( iface.name().empty() )
iface = Poco::Net::NetworkInterface::forAddress(Poco::Net::IPAddress(ifaceaddr));
if( iface.name().empty() )
{
if( throwEx )
{
ostringstream err;
err << "(MulticastReceiveTransport): Not found interface or address " << ifaceaddr;
throw uniset::SystemError(err.str());
}
return false;
}
}
udp = unisetstd::make_unique<MulticastSocketU>(host, port); udp = unisetstd::make_unique<MulticastSocketU>(host, port);
udp->setBlocking(!noblock); udp->setBlocking(!noblock);
...@@ -299,7 +357,7 @@ std::unique_ptr<MulticastSendTransport> MulticastSendTransport::createFromXml( U ...@@ -299,7 +357,7 @@ std::unique_ptr<MulticastSendTransport> MulticastSendTransport::createFromXml( U
if( numChan > 0 ) if( numChan > 0 )
ipField << numChan; ipField << numChan;
const string ip = it.getProp(ipField.str()); string ip = it.getProp(ipField.str());
if( ip.empty() ) if( ip.empty() )
{ {
...@@ -308,6 +366,30 @@ std::unique_ptr<MulticastSendTransport> MulticastSendTransport::createFromXml( U ...@@ -308,6 +366,30 @@ std::unique_ptr<MulticastSendTransport> MulticastSendTransport::createFromXml( U
throw SystemError(err.str()); throw SystemError(err.str());
} }
Poco::Net::NetworkInterface iface;
try
{
// check if ip is iface
iface = Poco::Net::NetworkInterface::forName(ip);
}
catch( const std::exception& ex ) {}
if( !iface.name().empty() )
{
auto al = iface.addressList();
if( al.empty() )
{
ostringstream err;
err << "(MulticastSendTransport): Unknown ip for interface " << ip;
throw SystemError(err.str());
}
// get first IP
ip = al[0].get<0>().toString();
}
int ttl = it.getPIntProp("unet_multicast_ttl", 1); int ttl = it.getPIntProp("unet_multicast_ttl", 1);
return unisetstd::make_unique<MulticastSendTransport>(ip, p, h, p, ttl); return unisetstd::make_unique<MulticastSendTransport>(ip, p, h, p, ttl);
} }
......
...@@ -112,9 +112,12 @@ namespace uniset ...@@ -112,9 +112,12 @@ namespace uniset
подписываться каждый receiver и в которую будет писать соответствующий sender. подписываться каждый receiver и в которую будет писать соответствующий sender.
По умолчанию для подключения к группе используется интерфейс ANY, но параметром По умолчанию для подключения к группе используется интерфейс ANY, но параметром
unet_multicast_iface="192.168.1.1" можно задать интерфейс через который ожидаются multicast-пакеты. unet_multicast_iface="192.168.1.1" можно задать интерфейс через который ожидаются multicast-пакеты.
Поддерживается текстовое задание интерфейса в виде unet_multicast_iface="eth0"
Для посылающего процесса можно определить параметр \b unet_multicast_ttl задающий время жизни multicast пакетов. Для посылающего процесса можно определить параметр \b unet_multicast_ttl задающий время жизни multicast пакетов.
По умолчанию ttl=1. А так же определить ip для сокета параметром \b unet_multicast_sender_ip. По умолчанию "0.0.0.0". По умолчанию ttl=1. А так же определить ip для сокета параметром \b unet_multicast_sender_ip. По умолчанию "0.0.0.0".
Можно задавать текстовое название интерфейса unet_multicast_sender_ip="eth0", при этом
в качестве ip будет взят \b первый ip-адрес из привязанных к указанному интерфейсу.
В данной реализации поддерживается работа в два канала. Соответствующие настройки для второго канала имеют индекс "2". В данной реализации поддерживается работа в два канала. Соответствующие настройки для второго канала имеют индекс "2".
unet_multicast_ip2, unet_multicast_port2, unet_multicast_iface2 unet_multicast_ip2, unet_multicast_port2, unet_multicast_iface2
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment