+ @test_util.skipUnless(test_util.pl_auth() is not None,
+ "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)")
+ @test_util.skipUnless(os.environ.get('NEPI_FULL_TESTS','').lower() in ('1','yes','true','on'),
+ "Test is expensive, requires NEPI_FULL_TESTS=yes")
+ def test_ns3_in_pl_snat(self):
+ pl, exp = self.make_experiment_desc()
+
+ # Create PL node, ifaces, assign addresses
+ node1, iface1, tap1, tap1ip, inet = self.make_pl_tapnode(pl)
+
+ # Add NS3 support in node1
+ ns3_desc = self.make_ns_in_pl(pl, exp, node1, iface1, "tb-ns3-3")
+
+ # Enable SNAT
+ tap1.set_attribute_value("snat", True)
+
+ # Add second PL node (ping target)
+ node2 = pl.create("Node")
+ node2.set_attribute_value("hostname", self.host2)
+ node2.set_attribute_value("label", "node2")
+ iface2 = pl.create("NodeInterface")
+ iface2.set_attribute_value("label", "node2iface")
+ node2.connector("devs").connect(iface2.connector("node"))
+ iface2.connector("inet").connect(inet.connector("devs"))
+
+ # Create NS3 node that is responsive to pings, connected
+ # to node1 through the Tap interface
+ ns1 = ns3_desc.create("ns3::Node")
+ ipv41 = ns3_desc.create("ns3::Ipv4L3Protocol")
+ arp1 = ns3_desc.create("ns3::ArpL3Protocol")
+ icmp1 = ns3_desc.create("ns3::Icmpv4L4Protocol")
+ ns1.connector("protos").connect(ipv41.connector("node"))
+ ns1.connector("protos").connect(arp1.connector("node"))
+ ns1.connector("protos").connect(icmp1.connector("node"))
+ ns1if = ns3_desc.create("ns3::FdNetDevice")
+ ns1if.enable_trace("FdPcapTrace")
+ ns1if.set_attribute_value("label", "ns1if")
+ ns1.connector("devs").connect(ns1if.connector("node"))
+ tap1.connector("fd->").connect(ns1if.connector("->fd"))
+ ip1 = ns1if.add_address()
+ ip1.set_attribute_value("Address", "192.168.2.3")
+ ip1.set_attribute_value("NetPrefix", 24)
+ ip1.set_attribute_value("Broadcast", False)
+
+ # Add default route to the PL node
+ r1 = ns1.add_route()
+ r1.set_attribute_value("Destination", "0.0.0.0")
+ r1.set_attribute_value("NetPrefix", 0)
+ r1.set_attribute_value("NextHop", "192.168.2.2")
+
+ # Create NS3 ping application, pinging the PL node
+ ping = ns3_desc.create("ns3::V4Ping")
+ ping.set_attribute_value("Remote", "{#[node2iface].addr[0].[Address]#}")
+ ping.set_attribute_value("StartTime", "0s")
+ ping.set_attribute_value("StopTime", "10s")
+ ping.connector("node").connect(ns1.connector("apps"))
+
+ xml = exp.to_xml()
+
+ try:
+ controller = ExperimentController(xml, self.root_dir)
+ controller.start()
+
+ while not controller.is_finished(ping.guid):
+ time.sleep(0.5)
+
+ tap_trace = controller.trace(tap1.guid, "packets")
+
+ finally:
+ try:
+ controller.stop()
+ except:
+ import traceback
+ traceback.print_exc()
+ try:
+ controller.shutdown()
+ except:
+ import traceback
+ traceback.print_exc()
+
+ # asserts at the end, to make sure there's proper cleanup
+ sent = 0
+ replied = 0
+ for seq in xrange(10):
+ re_send = r""".*
+[0-9.:]* IP 192.168.2.3 > (\d*\.){3}\d*: ICMP echo request, id 0, seq %(seq)d, length \d*
+.*""" % dict(seq=seq)
+
+ re_reply = r""".*
+[0-9.:]* IP 192.168.2.3 > (\d*\.){3}\d*: ICMP echo request, id 0, seq %(seq)d, length \d*.*
+[0-9.:]* IP (\d*\.){3}\d* > 192.168.2.3: ICMP echo reply, id 0, seq %(seq)d, length \d*
+.*""" % dict(seq=seq)
+
+ sent += bool(re.match(re_send, tap_trace, re.MULTILINE|re.DOTALL))
+ replied += bool(re.match(re_reply, tap_trace, re.MULTILINE|re.DOTALL))
+
+ self.assertTrue(sent == replied and sent > 5,
+ "Unexpected trace:\n%s\n" % (
+ tap_trace,) )
+
+ def _test_ns3_in_pl_p2p(self, proto):
+ pl, exp = self.make_experiment_desc()
+
+ # Create PL node, ifaces, assign addresses
+ node1, iface1, (tap0,tap1), (tap0ip,tap1ip), inet = self.make_pl_tapnode(pl,
+ label="node1", hostname = self.host1,
+ ip=["192.168.2.2","192.168.2.5"])
+ node2, iface2, (tap2,tap3), (tap2ip,tap3ip), inet = self.make_pl_tapnode(pl, inet=inet,
+ label="node2", hostname = self.host2,
+ ip=["192.168.2.6","192.168.2.9"])
+ node3, iface3, tap4, tap4ip, inet = self.make_pl_tapnode(pl, inet=inet,
+ label="node3", hostname = self.host3,
+ ip="192.168.2.10")
+
+ # Add NS3 support in node1
+ ns3_desc = self.make_ns_in_pl(pl, exp, node1, iface1, "tb-ns3-4-%s" % (proto,))
+
+ # Configure P2P links
+ tap0.set_attribute_value("pointopoint", "192.168.2.1") # cross-p2p is not automatic
+ tap1.connector(proto).connect(tap2.connector(proto))
+ tap3.connector(proto).connect(tap4.connector(proto))
+
+ # Configure routes
+ r = node1.add_route()
+ r.set_attribute_value("Destination", "192.168.2.8")
+ r.set_attribute_value("NetPrefix", 29)
+ r.set_attribute_value("NextHop", "192.168.2.6")
+
+ r = node2.add_route()
+ r.set_attribute_value("Destination", "192.168.2.0")
+ r.set_attribute_value("NetPrefix", 29)
+ r.set_attribute_value("NextHop", "192.168.2.5")
+
+ r = node3.add_route()
+ r.set_attribute_value("Destination", "192.168.2.0")
+ r.set_attribute_value("NetPrefix", 29)
+ r.set_attribute_value("NextHop", "192.168.2.9")
+
+ # Create NS3 node that is responsive to pings, connected
+ # to node1 through the Tap interface
+ ns1 = ns3_desc.create("ns3::Node")
+ ipv41 = ns3_desc.create("ns3::Ipv4L3Protocol")
+ arp1 = ns3_desc.create("ns3::ArpL3Protocol")
+ icmp1 = ns3_desc.create("ns3::Icmpv4L4Protocol")
+ ns1.connector("protos").connect(ipv41.connector("node"))
+ ns1.connector("protos").connect(arp1.connector("node"))
+ ns1.connector("protos").connect(icmp1.connector("node"))
+ ns1if = ns3_desc.create("ns3::FdNetDevice")
+ ns1if.enable_trace("FdPcapTrace")
+ ns1if.set_attribute_value("label", "ns1if")
+ ns1.connector("devs").connect(ns1if.connector("node"))
+ tap0.connector("fd->").connect(ns1if.connector("->fd"))
+ ip1 = ns1if.add_address()
+ ip1.set_attribute_value("Address", "192.168.2.1")
+ ip1.set_attribute_value("NetPrefix", 30)
+ ip1.set_attribute_value("Broadcast", False)
+
+ # Add default route to the PL node
+ r1 = ns1.add_route()
+ r1.set_attribute_value("Destination", "0.0.0.0")
+ r1.set_attribute_value("NetPrefix", 0)
+ r1.set_attribute_value("NextHop", "192.168.2.2")
+
+ # Create NS3 ping application, pinging the PL node
+ ping = ns3_desc.create("ns3::V4Ping")
+ ping.set_attribute_value("Remote", "{#[node3tap].addr[0].[Address]#}")
+ ping.set_attribute_value("StartTime", "0s")
+ ping.set_attribute_value("StopTime", "10s")
+ ping.connector("node").connect(ns1.connector("apps"))
+
+ xml = exp.to_xml()
+
+ try:
+ controller = ExperimentController(xml, self.root_dir)
+ controller.start()
+
+ while not controller.is_finished(ping.guid):
+ time.sleep(0.5)
+
+ tap_trace = []
+ for i,tap in enumerate([ tap0, tap1, tap2, tap3, tap4 ]):
+ tap_trace.append("\nTrace for tap%d:\n" % i)
+ tap_trace.append(controller.trace(tap.guid, "packets"))
+ tap_trace = "".join(tap_trace)
+ tap0_trace = controller.trace(tap0.guid, "packets")
+
+ finally:
+ try:
+ controller.stop()
+ except:
+ import traceback
+ traceback.print_exc()
+ try:
+ controller.shutdown()
+ except:
+ import traceback
+ traceback.print_exc()
+
+ # asserts at the end, to make sure there's proper cleanup
+ sent = 0
+ replied = 0
+ for seq in xrange(10):
+ re_send = r""".*
+[0-9.:]* IP 192.168.2.1 > (\d*\.){3}\d*: ICMP echo request, id 0, seq %(seq)d, length \d*
+.*""" % dict(seq=seq)
+
+ re_reply = r""".*
+[0-9.:]* IP 192.168.2.1 > (\d*\.){3}\d*: ICMP echo request, id 0, seq %(seq)d, length \d*.*
+[0-9.:]* IP (\d*\.){3}\d* > 192.168.2.1: ICMP echo reply, id 0, seq %(seq)d, length \d*
+.*""" % dict(seq=seq)
+
+ sent += bool(re.match(re_send, tap0_trace, re.MULTILINE|re.DOTALL))
+ replied += bool(re.match(re_reply, tap0_trace, re.MULTILINE|re.DOTALL))
+
+ self.assertTrue(replied >= sent/2 and sent > 5,
+ "Unexpected trace:\n%s\n" % (
+ tap_trace,) )
+
+
+ @test_util.skipUnless(test_util.pl_auth() is not None,
+ "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)")
+ @test_util.skipUnless(os.environ.get('NEPI_FULL_TESTS','').lower() in ('1','yes','true','on'),
+ "Test is expensive, requires NEPI_FULL_TESTS=yes")
+ def test_ns3_in_pl_p2p_udp(self):
+ self._test_ns3_in_pl_p2p("udp")
+
+ @test_util.skipUnless(test_util.pl_auth() is not None,
+ "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)")
+ @test_util.skipUnless(os.environ.get('NEPI_FULL_TESTS','').lower() in ('1','yes','true','on'),
+ "Test is expensive, requires NEPI_FULL_TESTS=yes")
+ def test_ns3_in_pl_p2p_tcp(self):
+ self._test_ns3_in_pl_p2p("tcp")
+