2 # NEPI, a framework to manage network experiments
3 # Copyright (C) 2014 INRIA
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License version 2 as
7 # published by the Free Software Foundation;
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 # Author: Alina Quereilhac <alina.quereilhac@inria.fr>
19 from nepi.execution.attribute import Attribute, Flags, Types
20 from nepi.execution.resource import clsinit_copy
21 from nepi.resources.ns3.ns3base import NS3Base
26 class NS3BasePipeChannel(NS3Base):
27 """ Interconnects two FdNetDevices with a PIPE
29 _rtype = "ns3::PipeChannel"
31 def __init__(self, ec, guid):
32 super(NS3BasePipeChannel, self).__init__(ec, guid)
38 from nepi.resources.ns3.ns3fdnetdevice import NS3BaseFdNetDevice
39 devices = self.get_connected(NS3BaseFdNetDevice.get_rtype())
40 if not devices or len(devices) != 2:
41 msg = "PipeChannel must be connected to exactly to two FdNetDevices"
43 raise RuntimeError(msg)
45 self._devices = devices
51 return self.devices[0].node
54 def _rms_to_wait(self):
55 rms = set(self.devices)
58 def _instantiate_object(self):
59 """ The pipe channel does not really exists as an ns-3 object.
64 def _connect_object(self):
65 dev1 = self.devices[0]
66 dev2 = self.devices[1]
68 if dev1.uuid not in self.connected and dev2.uuid not in self.connected:
69 (s0, s1) = socket.socketpair(socket.AF_UNIX, socket.SOCK_STREAM, 0)
73 self._connected.add(dev1.uuid)
74 dev1._connected.add(self.uuid)
78 self._connected.add(dev2.uuid)
79 dev2._connected.add(self.uuid)