from nepi.execution.attribute import Attribute, Flags
from nepi.execution.resource import clsinit_copy
+from nepi.execution.trace import Trace
from nepi.resources.ns3.ns3base import NS3Base
import ipaddr
cls._register_attribute(ip)
cls._register_attribute(prefix)
+ @classmethod
+ def _register_traces(cls):
+ pcap = Trace("pcap", "Dump traffic sniffed on the network device in Pcap format")
+ promisc_pcap = Trace("promiscPcap", "Dump traffic sniffed in promiscuous mode on the network device in Pcap format")
+ ascii = Trace("ascii", "Dump traffic sniffed on the network device in Ascii format")
+
+ cls._register_trace(pcap)
+ cls._register_trace(promisc_pcap)
+ cls._register_trace(ascii)
+
+ def __init__(self, ec, guid):
+ super(NS3BaseNetDevice, self).__init__(ec, guid)
+ self._ascii_helper_uuid = None
+ self._device_helper_uuid = None
+
@property
def node(self):
from nepi.resources.ns3.ns3node import NS3BaseNode
return channels[0]
+ @property
+ def ascii_helper_uuid(self):
+ if not self._ascii_helper_uuid:
+ self._ascii_helper_uuid = self.simulation.create("AsciiTraceHelper")
+ return self._ascii_helper_uuid
+
+ @property
+ def device_helper_uuid(self):
+ if not self._device_helper_uuid:
+ rtype = self.get_rtype()
+ if rtype == "ns3::PointToPointNetDevice":
+ classname = "PointToPointHelper"
+ elif rtype == "ns3::CsmaNetDevice":
+ classname = "CsmaHelper"
+ elif rtype == "ns3::EmuNetDevice":
+ classname = "EmuHelper"
+ elif rtype == "ns3::FdNetDevice":
+ classname = "FdNetDeviceHelper"
+ elif rtype in [ "ns3::BaseStationNetDevice", "SubscriberStationNetDevice" ]:
+ classname = "WimaxHelper"
+ elif rtype == "ns3::WifiNetDevice":
+ classname = "YansWifiPhyHelper"
+
+ self._device_helper_uuid = self.simulation.create(classname)
+
+ return self._device_helper_uuid
+
@property
def _rms_to_wait(self):
others = set()
# IPv6
# TODO!
pass
+
+ # Enable traces
+ self._configure_traces()
+
+ def _configure_traces(self):
+ if self.trace_enabled("pcap"):
+ helper_uuid = self.device_helper_uuid
+
+ filename = "trace-pcap-netdev-%d.pcap" % self.guid
+ self._trace_filename["pcap"] = filename
+
+ filepath = self.simulation.trace_filepath(filename)
+
+ self.simulation.invoke(helper_uuid, "EnablePcap", filepath,
+ self.uuid, promiscuous = False, explicitFilename = True)
+
+ if self.trace_enabled("promiscPcap"):
+ helper_uuid = self.device_helper_uuid
+
+ filename = "trace-promisc-pcap-netdev-%d.pcap" % self.guid
+ self._trace_filename["promiscPcap"] = filename
+
+ filepath = self.simulation.trace_filepath(filename)
+
+ self.simulation.invoke(helper_uuid, "EnablePcap", filepath,
+ self.uuid, promiscuous = True, explicitFilename = True)
+
+ if self.trace_enabled("ascii"):
+ helper_uuid = self.device_helper_uuid
+ ascii_helper_uuid = self.ascii_helper_uuid
+
+ filename = "trace-ascii-netdev-%d.tr" % self.guid
+ self._trace_filename["ascii"] = filename
+
+ filepath = self.simulation.trace_filepath(filename)
+ stream_uuid = self.simulation.invoke(ascii_helper_uuid,
+ "CreateFileStream", filepath)
+ self.simulation.invoke(helper_uuid, "EnableAscii", stream_uuid,
+ self.uuid)
def _connect_object(self):
node = self.node