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 as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 # Author: Alina Quereilhac <alina.quereilhac@inria.fr>
20 from nepi.execution.attribute import Attribute, Flags, Types
21 from nepi.execution.resource import clsinit_copy
22 from nepi.resources.ns3.ns3base import NS3Base
27 class NS3BasePipeChannel(NS3Base):
28 """ Interconnects two FdNetDevices with a PIPE
30 _rtype = "ns3::PipeChannel"
32 def __init__(self, ec, guid):
33 super(NS3BasePipeChannel, self).__init__(ec, guid)
39 from nepi.resources.ns3.ns3fdnetdevice import NS3BaseFdNetDevice
40 devices = self.get_connected(NS3BaseFdNetDevice.get_rtype())
41 if not devices or len(devices) != 2:
42 msg = "PipeChannel must be connected to exactly to two FdNetDevices"
44 raise RuntimeError, msg
46 self._devices = devices
52 return self.devices[0].node
55 def _rms_to_wait(self):
56 rms = set(self.devices)
59 def _instantiate_object(self):
60 """ The pipe channel does not really exists as an ns-3 object.
65 def _connect_object(self):
66 dev1 = self.devices[0]
67 dev2 = self.devices[1]
69 if dev1.uuid not in self.connected and dev2.uuid not in self.connected:
70 (s0, s1) = socket.socketpair(socket.AF_UNIX, socket.SOCK_STREAM, 0)
74 self._connected.add(dev1.uuid)
75 dev1._connected.add(self.uuid)
79 self._connected.add(dev2.uuid)
80 dev2._connected.add(self.uuid)