From 8a979c4eae145266a5fbdac86dd3d77964e9f6f2 Mon Sep 17 00:00:00 2001 From: Ting Hsuan Hsieh Date: Wed, 12 Oct 2016 21:34:22 +0800 Subject: [PATCH] Remove mininet-patch * All mininet-patch will be tracked in mininet repository --- .../roles/dlinknctu-mininet/tasks/main.yml | 10 - mininet-patch/examples/cluster/gre.py | 72 -- .../cluster/leaf-spine-topo-cluster.py | 28 - .../nctu_ec_wired_and_wireless_topo.py | 137 --- .../examples/cluster/nctu_ec_wired_topo.py | 88 -- .../cluster/simple-cluster-opennet.py | 89 -- .../examples/cluster/simple-cluster.py | 71 -- .../examples/cluster/tree-topo-cluster.py | 39 - mininet-patch/examples/cluster/vxlan.py | 72 -- mininet-patch/examples/ns3/Ap-trace.pcap | Bin 9132 -> 0 bytes mininet-patch/examples/ns3/README.md | 8 - mininet-patch/examples/ns3/csma-link-pcap.py | 46 - mininet-patch/examples/ns3/csma-link.py | 36 - mininet-patch/examples/ns3/emptynet-csma.py | 49 - mininet-patch/examples/ns3/emptynet-simple.py | 49 - .../examples/ns3/emptynet-wifi-bridge.py | 55 - mininet-patch/examples/ns3/emptynet-wifi.py | 53 - mininet-patch/examples/ns3/simple-link.py | 37 - mininet-patch/examples/ns3/simple-segment.py | 45 - mininet-patch/examples/ns3/start-stop.py | 6 - mininet-patch/examples/ns3/tbintf.py | 72 -- mininet-patch/examples/ns3/wifi-adhoc.py | 46 - mininet-patch/examples/ns3/wifi-ap-pcap.py | 46 - mininet-patch/examples/ns3/wifi-ap.py | 46 - mininet-patch/examples/ns3/wifi-positions.py | 64 -- .../examples/ns3/wifi-rate-anomaly.py | 68 -- .../examples/opennet/ap-sta-switch-host.py | 71 -- .../examples/opennet/two-ap-one-sw.py | 82 -- mininet-patch/examples/opennet/wifiroaming.py | 208 ---- mininet-patch/mininet/ns3.py | 944 ------------------ mininet-patch/mininet/opennet.py | 99 -- 31 files changed, 2736 deletions(-) delete mode 100644 mininet-patch/examples/cluster/gre.py delete mode 100644 mininet-patch/examples/cluster/leaf-spine-topo-cluster.py delete mode 100644 mininet-patch/examples/cluster/nctu_ec_wired_and_wireless_topo.py delete mode 100644 mininet-patch/examples/cluster/nctu_ec_wired_topo.py delete mode 100644 mininet-patch/examples/cluster/simple-cluster-opennet.py delete mode 100644 mininet-patch/examples/cluster/simple-cluster.py delete mode 100644 mininet-patch/examples/cluster/tree-topo-cluster.py delete mode 100644 mininet-patch/examples/cluster/vxlan.py delete mode 100644 mininet-patch/examples/ns3/Ap-trace.pcap delete mode 100644 mininet-patch/examples/ns3/README.md delete mode 100644 mininet-patch/examples/ns3/csma-link-pcap.py delete mode 100644 mininet-patch/examples/ns3/csma-link.py delete mode 100644 mininet-patch/examples/ns3/emptynet-csma.py delete mode 100644 mininet-patch/examples/ns3/emptynet-simple.py delete mode 100644 mininet-patch/examples/ns3/emptynet-wifi-bridge.py delete mode 100644 mininet-patch/examples/ns3/emptynet-wifi.py delete mode 100644 mininet-patch/examples/ns3/simple-link.py delete mode 100644 mininet-patch/examples/ns3/simple-segment.py delete mode 100644 mininet-patch/examples/ns3/start-stop.py delete mode 100644 mininet-patch/examples/ns3/tbintf.py delete mode 100644 mininet-patch/examples/ns3/wifi-adhoc.py delete mode 100644 mininet-patch/examples/ns3/wifi-ap-pcap.py delete mode 100644 mininet-patch/examples/ns3/wifi-ap.py delete mode 100644 mininet-patch/examples/ns3/wifi-positions.py delete mode 100644 mininet-patch/examples/ns3/wifi-rate-anomaly.py delete mode 100644 mininet-patch/examples/opennet/ap-sta-switch-host.py delete mode 100644 mininet-patch/examples/opennet/two-ap-one-sw.py delete mode 100644 mininet-patch/examples/opennet/wifiroaming.py delete mode 100644 mininet-patch/mininet/ns3.py delete mode 100644 mininet-patch/mininet/opennet.py diff --git a/ansible/roles/dlinknctu-mininet/tasks/main.yml b/ansible/roles/dlinknctu-mininet/tasks/main.yml index e811a45..d036922 100644 --- a/ansible/roles/dlinknctu-mininet/tasks/main.yml +++ b/ansible/roles/dlinknctu-mininet/tasks/main.yml @@ -11,16 +11,6 @@ accept_hostkey: true version: "opennet" tags: mininet -- name: Add exmaples from OpenNet - copy: - src: "{{ home_location }}/mininet-patch/examples/" - dest: "{{ home_location }}/mininet/examples/" - tags: mininet -- name: Add new module from OpenNet - copy: - src: "{{ home_location }}/mininet-patch/mininet/" - dest: "{{ home_location }}/mininet/mininet" - tags: mininet - name: Install dlinknctu-mininet command: "./util/install.sh -n" args: diff --git a/mininet-patch/examples/cluster/gre.py b/mininet-patch/examples/cluster/gre.py deleted file mode 100644 index 85badf0..0000000 --- a/mininet-patch/examples/cluster/gre.py +++ /dev/null @@ -1,72 +0,0 @@ -#!/usr/bin/python - -""" -gre.py - -mininet1 mininet2 --------- -------- -| | | | -| s1=========s2 | -| | | | | | -| h1 | | h2 | -| | | | --------- -------- - -=== : cross-link -| : link - -Testing enviroment (cat /etc/hosts) : -192.168.59.100 mininet1 -192.168.59.101 mininet2 -""" - -# from mininet.examples.cluster import MininetCluster -from mininet.log import setLogLevel -from mininet.node import Controller, RemoteController -from mininet.link import Link, Intf -from mininet.util import quietRun, errRun - -from mininet.cluster.node import * -from mininet.cluster.net import * -from mininet.cluster.placer import * -from mininet.cluster.link import * -from mininet.cluster.clean import * -from mininet.cluster.cli import ClusterCLI as CLI - - -def demo(): - CONTROLLER_IP="192.168.59.100" - CONTROLLER_PORT=6633 - servers = [ 'mininet1', 'mininet2' ] - - net = MininetCluster( controller=RemoteController, servers=servers) - - c0 = net.addController( 'c0', controller=RemoteController, ip=CONTROLLER_IP, port=CONTROLLER_PORT) - - # In mininet1 - s1 = net.addSwitch('s1') - h1 = net.addHost('h1', ip="10.0.0.1") - net.addLink(s1, h1) - - # In mininet2 - s2 = net.addSwitch('s2', server="mininet2") - h2 = net.addHost('h2', ip="10.0.0.2", server="mininet2") - net.addLink(s2, h2) - - net.start() - # Cross-link between mininet1 and mininet2 - s1_endpoint_address = "192.168.59.100" - s2_endpoint_address = "192.168.59.101" - key = "99" - s1.cmdPrint("ovs-vsctl add-port s1 s1-eth2 -- set interface s1-eth2 type=gre options:local_ip=" + s1_endpoint_address + " options:remote_ip=" + s2_endpoint_address + " options:key=" + key) - s2.cmdPrint("ovs-vsctl add-port s2 s2-eth2 -- set interface s2-eth2 type=gre options:local_ip=" + s2_endpoint_address + " options:remote_ip=" + s1_endpoint_address + " options:key=" + key) - - info("Recommand command:\n") - info("$ tcpdump -i eth0 proto GRE\n") - - CLI( net ) - net.stop() - -if __name__ == '__main__': - setLogLevel( 'info' ) - demo() diff --git a/mininet-patch/examples/cluster/leaf-spine-topo-cluster.py b/mininet-patch/examples/cluster/leaf-spine-topo-cluster.py deleted file mode 100644 index 4504903..0000000 --- a/mininet-patch/examples/cluster/leaf-spine-topo-cluster.py +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/python -""" -leaf-spine-topo-cluster.py - -mininet1: 192.168.59.100 -mininet2: 192.168.59.101 -""" - -from mininet.cluster.net import MininetCluster -from mininet.cluster.placer import DFSPlacer -from mininet.topolib import LeafSpineTopo -from mininet.log import setLogLevel -from mininet.cluster.cli import ClusterCLI as CLI -from mininet.node import Controller, RemoteController - -def tree_topo_cluster(): - servers = [ 'mininet1', 'mininet2' ] - topo = LeafSpineTopo( leaf=2, spine=2, fanout=2 ) - net = MininetCluster( controller=RemoteController, topo=topo, servers=servers, - placement=DFSPlacer, root_node="spine1", tunneling="vxlan" ) - net.addController( 'controller', controller=RemoteController, ip="192.168.59.100", port=6633) - net.start() - CLI( net ) - net.stop() - -if __name__ == '__main__': - setLogLevel( 'info' ) - tree_topo_cluster() diff --git a/mininet-patch/examples/cluster/nctu_ec_wired_and_wireless_topo.py b/mininet-patch/examples/cluster/nctu_ec_wired_and_wireless_topo.py deleted file mode 100644 index 83bb869..0000000 --- a/mininet-patch/examples/cluster/nctu_ec_wired_and_wireless_topo.py +++ /dev/null @@ -1,137 +0,0 @@ -#!/usr/bin/python -''' -nctu_cs_wired_and_wireless_topo.gy -''' - -from mininet.cluster.net import MininetCluster -from mininet.cluster.placer import DFSPlacer -from mininet.log import setLogLevel -from mininet.cluster.cli import ClusterCLI as CLI -from mininet.node import Controller, RemoteController -from mininet.topo import Topo -from itertools import combinations -import mininet.ns3 -from mininet.ns3 import WifiSegment - -CONTROLLER_IP = "192.168.59.100" -CONTROLLER_PORT = 6633 - -SERVER_LIST = [ 'mininet1', 'mininet2' ] - -class NCTU_EC_Topology( Topo ): - - def __init__(self, core=1, agg=6, access=6, host=5, *args, **kwargs): - Topo.__init__(self, *args, **kwargs) - self.core_num = core - self.agg_num = agg - self.access_num = access - self.host_num = host - self.sw_id = 1 - self.host_id = 1 - - # Init switch and host list - self.core_sw_list = [] - self.agg_sw_list = [] - self.access_sw_list = [] - self.host_list = [] - - self.create_top_switch( "core", self.core_num, self.core_sw_list ) - - self.handle_top_down( "agg", self.agg_num, self.core_sw_list, self.agg_sw_list ) - self.handle_top_down( "access", self.access_num, self.agg_sw_list, self.access_sw_list ) - - self.handle_host( "h", self.host_num, self.host_list ) - - self.handle_mesh( self.agg_sw_list ) - - def create_top_switch( self, prefix_name, sw_num, sw_list): - for i in xrange(1, sw_num+1): - sw_list.append(self.addSwitch("{0}{1}".format(prefix_name, i), dpid='{0:x}'.format(self.sw_id))) - self.sw_id += 1 - - def handle_top_down( self, prefix_name, num, top_list, down_list): - temp = 0 - for i in xrange(0, len(top_list)): - for j in xrange(1, num+1): - switch = self.addSwitch("{0}{1}".format(prefix_name, j + temp), dpid='{0:x}'.format(self.sw_id)) - self.addLink(top_list[i], switch) - down_list.append(switch) - self.sw_id += 1 - temp = j - - - def handle_host( self, prefix_name, host_num, host_list ): - for i in xrange(0, len(self.access_sw_list)): - for j in xrange(0, host_num): - host = self.addHost('{0}{1}'.format(prefix_name, self.host_id)) - # Link to access sw - self.addLink(self.access_sw_list[i], host) - # Append host to list - host_list.append(host) - self.host_id += 1 - - def handle_mesh( self, sw_list ): - for link in combinations(sw_list, 2): - self.addLink(link[0], link[1]) - - -def RunTestBed(): - - # NCTU_EC_Topology( Core Switch, Aggregate Switch, Access Switch, Host) - topo = NCTU_EC_Topology(core=1, agg=3, access=3, host=2) - - net = MininetCluster( controller=RemoteController, topo=topo, servers=SERVER_LIST, placement=DFSPlacer, root_node="core1", tunneling="vxlan" ) - net.addController( 'controller', controller=RemoteController, ip=CONTROLLER_IP, port=CONTROLLER_PORT ) - - wifi = WifiSegment() - - """ - Create AP - """ - ap_to_access_sw = 0 - for i in xrange(1): - AP_NAME = "ap" + str(i) - ap = net.addSwitch(AP_NAME, server=SERVER_LIST[0]) - mininet.ns3.setMobilityModel(ap, None) - mininet.ns3.setPosition(ap, 0, 0, 0) - wifi.addAp(ap, channelNumber=6, ssid="opennet-ap", port=0) - net.addLink(ap, topo.access_sw_list[ap_to_access_sw]) - ap_to_access_sw += 1 - - """ - Create Station - """ - STA_NAME = "sta" + str(0) - sta = net.addHost(STA_NAME, server=SERVER_LIST[0]) - mininet.ns3.setMobilityModel(sta, None) - mininet.ns3.setPosition(sta, 0, 0, 0) - wifi.addSta(sta, channelNumber=6, ssid="opennet-ap", port=0) - - net.start() - mininet.ns3.start() - - """ - Post Handle - """ - # XXX Need to fixed - AP_NAME = "ap" + str(0) - cmd = "ovs-vsctl add-port {0} {0}-eth0".format(AP_NAME) - net.getNodeByName(AP_NAME).cmdPrint(cmd) - - STA_NAME = "sta" + str(0) - cmd = "ip addr add 10.0.0.{0}/8 dev {1}-eth0".format(str(200+i), STA_NAME) - net.getNodeByName(STA_NAME).cmdPrint(cmd) - net.getNodeByName(STA_NAME).cmdPrint("ip addr show dev {0}-eth0".format(STA_NAME)) - - """ - Show interface object in ns3 - """ - print("*** allTBintfs: {0}\n".format(mininet.ns3.allTBIntfs)) - CLI( net ) - mininet.ns3.stop() - mininet.ns3.clear() - net.stop() - -if __name__ == '__main__': - setLogLevel('info') - RunTestBed() diff --git a/mininet-patch/examples/cluster/nctu_ec_wired_topo.py b/mininet-patch/examples/cluster/nctu_ec_wired_topo.py deleted file mode 100644 index e2e97b9..0000000 --- a/mininet-patch/examples/cluster/nctu_ec_wired_topo.py +++ /dev/null @@ -1,88 +0,0 @@ -#!/usr/bin/python -''' -nctu_cs_wired_topo.gy -''' - -from mininet.cluster.net import MininetCluster -from mininet.cluster.placer import DFSPlacer -from mininet.log import setLogLevel -from mininet.cluster.cli import ClusterCLI as CLI -from mininet.node import Controller, RemoteController -from mininet.topo import Topo -from itertools import combinations - -CONTROLLER_IP = "192.168.59.100" -CONTROLLER_PORT = 6633 -SERVER_LIST = [ 'mininet1', 'mininet2' ] - -class NCTU_EC_Topology( Topo ): - - def __init__(self, core=1, agg=6, access=6, host=5, *args, **kwargs): - Topo.__init__(self, *args, **kwargs) - self.core_num = core - self.agg_num = agg - self.access_num = access - self.host_num = host - self.sw_id = 1 - self.host_id = 1 - - # Init switch and host list - self.core_sw_list = [] - self.agg_sw_list = [] - self.access_sw_list = [] - self.host_list = [] - - self.create_top_switch( "core", self.core_num, self.core_sw_list ) - - self.handle_top_down( "agg", self.agg_num, self.core_sw_list, self.agg_sw_list ) - self.handle_top_down( "access", self.access_num, self.agg_sw_list, self.access_sw_list ) - - self.handle_host( "h", self.host_num, self.host_list ) - - self.handle_mesh( self.agg_sw_list ) - - def create_top_switch( self, prefix_name, sw_num, sw_list): - for i in xrange(1, sw_num+1): - sw_list.append(self.addSwitch("{0}{1}".format(prefix_name, i), dpid='{0:x}'.format(self.sw_id))) - self.sw_id += 1 - - def handle_top_down( self, prefix_name, num, top_list, down_list): - temp = 0 - for i in xrange(0, len(top_list)): - for j in xrange(1, num+1): - switch = self.addSwitch("{0}{1}".format(prefix_name, j + temp), dpid='{0:x}'.format(self.sw_id)) - self.addLink(top_list[i], switch) - down_list.append(switch) - self.sw_id += 1 - temp = j - - - def handle_host( self, prefix_name, host_num, host_list ): - for i in xrange(0, len(self.access_sw_list)): - for j in xrange(0, host_num): - host = self.addHost('{0}{1}'.format(prefix_name, self.host_id)) - # Link to access sw - self.addLink(self.access_sw_list[i], host) - # Append host to list - host_list.append(host) - self.host_id += 1 - - def handle_mesh( self, sw_list ): - for link in combinations(sw_list, 2): - self.addLink(link[0], link[1]) - -def RunTestBed(): - - # NCTU_EC_Topology( Core Switch, Aggregate Switch, Access Switch, Host) - topo = NCTU_EC_Topology(core=1, agg=6, access=6, host=20) - - net = MininetCluster( controller=RemoteController, topo=topo, servers=SERVER_LIST, placement=DFSPlacer, root_node="core1", tunneling="vxlan" ) - net.addController( 'controller', controller=RemoteController, ip=CONTROLLER_IP, port=CONTROLLER_PORT ) - net.start() - CLI( net ) - net.stop() - - -if __name__ == '__main__': - setLogLevel('info') - RunTestBed() diff --git a/mininet-patch/examples/cluster/simple-cluster-opennet.py b/mininet-patch/examples/cluster/simple-cluster-opennet.py deleted file mode 100644 index 9c81fae..0000000 --- a/mininet-patch/examples/cluster/simple-cluster-opennet.py +++ /dev/null @@ -1,89 +0,0 @@ -#!/usr/bin/python - -""" -simple-cluster-opennet.py - -mininet1 mininet2 --------- -------- -| | | | -| ap1========s2 | -| | | | | | -| sta1 | | h2 | -| | | | --------- -------- - -=== : cross-link -| : link - -Testing enviroment (cat /etc/hosts) : -192.168.59.100 mininet1 -192.168.59.101 mininet2 -""" - -from mininet.log import setLogLevel -from mininet.node import Controller, RemoteController -from mininet.link import Link, Intf -from mininet.util import quietRun, errRun - -from mininet.cluster.node import * -from mininet.cluster.net import * -from mininet.cluster.placer import * -from mininet.cluster.link import * -from mininet.cluster.clean import * -from mininet.cluster.cli import ClusterCLI as CLI - -import mininet.ns3 -from mininet.ns3 import WifiSegment - -import ns.core -import ns.network -import ns.wifi -import ns.csma - -def demo(): - CONTROLLER_IP="192.168.59.100" - CONTROLLER_PORT=6633 - servers = [ 'mininet1', 'mininet2' ] - - wifi = WifiSegment() - net = MininetCluster( controller=RemoteController, servers=servers) - c0 = net.addController( 'c0', controller=RemoteController, ip=CONTROLLER_IP, port=CONTROLLER_PORT) - - # In mininet1 - # ap1 - ap1 = net.addSwitch('ap1') - mininet.ns3.setMobilityModel(ap1, None) - mininet.ns3.setPosition(ap1, 0, 0, 0) - wifi.addAp(ap1, channelNumber=6, ssid="opennet_ap") - - # sta1 - sta1 = net.addHost('sta1', ip="10.0.0.1") - mininet.ns3.setMobilityModel(sta1, None) - mininet.ns3.setPosition(sta1, 0, 0, 0) - wifi.addSta(sta1, channelNumber=6, ssid="opennet_ap") - - # In mininet2 - s2 = net.addSwitch('s2', server="mininet2") - h2 = net.addHost('h2', ip="10.0.0.2", server="mininet2") - net.addLink(s2, h2) - - # Cross-link between mininet1 and mininet2 - net.addLink(ap1, s2) - - net.start() - mininet.ns3.start() - - print("Opennet is running on {hostname}".format(hostname=quietRun('hostname').strip())) - for node in c0, ap1, sta1, h2, s2: - print("Node {nodename} is running on {servername}".format(nodename=node, servername=node.cmd('hostname').strip())) - - net.pingAll() - CLI( net ) - - mininet.ns3.stop() - mininet.ns3.clear() - net.stop() - -if __name__ == '__main__': - setLogLevel( 'info' ) - demo() diff --git a/mininet-patch/examples/cluster/simple-cluster.py b/mininet-patch/examples/cluster/simple-cluster.py deleted file mode 100644 index 1fe27f4..0000000 --- a/mininet-patch/examples/cluster/simple-cluster.py +++ /dev/null @@ -1,71 +0,0 @@ -#!/usr/bin/python - -""" -simple-cluster.py - -mininet1 mininet2 --------- -------- -| | | | -| s1=========s2 | -| | | | | | -| h1 | | h2 | -| | | | --------- -------- - -=== : cross-link -| : link - -Testing enviroment (cat /etc/hosts) : -192.168.59.100 mininet1 -192.168.59.101 mininet2 -""" - -# from mininet.examples.cluster import MininetCluster -from mininet.log import setLogLevel -from mininet.node import Controller, RemoteController -from mininet.link import Link, Intf -from mininet.util import quietRun, errRun - -from mininet.cluster.node import * -from mininet.cluster.net import * -from mininet.cluster.placer import * -from mininet.cluster.link import * -from mininet.cluster.clean import * -from mininet.cluster.cli import ClusterCLI as CLI - - -def demo(): - CONTROLLER_IP="192.168.59.100" - CONTROLLER_PORT=6633 - servers = [ 'mininet1', 'mininet2' ] - - # Tunneling options: ssh (default), vxlan, gre - net = MininetCluster( controller=RemoteController, servers=servers, tunneling="vxlan") - # net = MininetCluster( controller=RemoteController, servers=servers) - - c0 = net.addController( 'c0', controller=RemoteController, ip=CONTROLLER_IP, port=CONTROLLER_PORT) - - # In mininet1 - s1 = net.addSwitch('s1') - h1 = net.addHost('h1', ip="10.0.0.1") - net.addLink(s1, h1) - - # In mininet2 - s2 = net.addSwitch('s2', server=servers[1]) - h2 = net.addHost('h2', ip="10.0.0.2", server=servers[1]) - net.addLink(s2, h2) - - # Cross-link between mininet1 and mininet2 - net.addLink(s1, s2) - - net.start() - print("Mininet is running on {hostname}".format(hostname=quietRun('hostname').strip())) - for node in c0, h1, s1, h2, s2: - print("Node {nodename} is running on {servername}".format(nodename=node, servername=node.cmd('hostname').strip())) - net.pingAll() - CLI( net ) - net.stop() - -if __name__ == '__main__': - setLogLevel( 'info' ) - demo() diff --git a/mininet-patch/examples/cluster/tree-topo-cluster.py b/mininet-patch/examples/cluster/tree-topo-cluster.py deleted file mode 100644 index 3716583..0000000 --- a/mininet-patch/examples/cluster/tree-topo-cluster.py +++ /dev/null @@ -1,39 +0,0 @@ -#!/usr/bin/python -""" -tree-topo-cluster.py - -s1====s3 -| | \ -s2 h3 h4 -| \ -h1 h2 - -===: cross-link -|: link - -ubuntu1: 192.168.59.100 -ubuntu2: 192.168.59.101 -""" - -from mininet.cluster.net import MininetCluster -from mininet.cluster.placer import SwitchBinPlacer -from mininet.topolib import TreeTopo -from mininet.log import setLogLevel -from mininet.cluster.cli import ClusterCLI as CLI -from mininet.node import Controller, RemoteController - -def tree_topo_cluster(): - servers = [ 'mininet1', 'mininet2' ] - topo = TreeTopo( depth=2, fanout=2 ) - # Tunneling options: ssh (default), vxlan, gre - net = MininetCluster( controller=RemoteController, topo=topo, servers=servers, - placement=SwitchBinPlacer, tunneling="gre" ) - net.addController( 'controller', controller=RemoteController, ip="192.168.59.100", port=6633) - net.start() - net.pingAll() - CLI( net ) - net.stop() - -if __name__ == '__main__': - setLogLevel( 'info' ) - tree_topo_cluster() diff --git a/mininet-patch/examples/cluster/vxlan.py b/mininet-patch/examples/cluster/vxlan.py deleted file mode 100644 index c88e7c8..0000000 --- a/mininet-patch/examples/cluster/vxlan.py +++ /dev/null @@ -1,72 +0,0 @@ -#!/usr/bin/python - -""" -vxlan.py - -mininet1 mininet2 --------- -------- -| | | | -| s1=========s2 | -| | | | | | -| h1 | | h2 | -| | | | --------- -------- - -=== : cross-link -| : link - -Testing enviroment (cat /etc/hosts) : -192.168.59.100 mininet1 -192.168.59.101 mininet2 -""" - -# from mininet.examples.cluster import MininetCluster -from mininet.log import setLogLevel -from mininet.node import Controller, RemoteController -from mininet.link import Link, Intf -from mininet.util import quietRun, errRun - -from mininet.cluster.node import * -from mininet.cluster.net import * -from mininet.cluster.placer import * -from mininet.cluster.link import * -from mininet.cluster.clean import * -from mininet.cluster.cli import ClusterCLI as CLI - - -def demo(): - CONTROLLER_IP="192.168.59.100" - CONTROLLER_PORT=6633 - servers = [ 'mininet1', 'mininet2' ] - - net = MininetCluster( controller=RemoteController, servers=servers) - - c0 = net.addController( 'c0', controller=RemoteController, ip=CONTROLLER_IP, port=CONTROLLER_PORT) - - # In mininet1 - s1 = net.addSwitch('s1') - h1 = net.addHost('h1', ip="10.0.0.1") - net.addLink(s1, h1) - - # In mininet2 - s2 = net.addSwitch('s2', server="mininet2") - h2 = net.addHost('h2', ip="10.0.0.2", server="mininet2") - net.addLink(s2, h2) - - net.start() - # Cross-link between mininet1 and mininet2 - s1_endpoint_address = "192.168.59.100" - s2_endpoint_address = "192.168.59.101" - key = "99" - s1.cmdPrint("ovs-vsctl add-port s1 s1-eth2 -- set interface s1-eth2 type=vxlan options:local_ip=" + s1_endpoint_address + " options:remote_ip=" + s2_endpoint_address + " options:key=" + key) - s2.cmdPrint("ovs-vsctl add-port s2 s2-eth2 -- set interface s2-eth2 type=vxlan options:local_ip=" + s2_endpoint_address + " options:remote_ip=" + s1_endpoint_address + " options:key=" + key) - - info("Recommand command:\n") - info("$ tcpdump -i eth0 udp port 4789\n") - - CLI( net ) - net.stop() - -if __name__ == '__main__': - setLogLevel( 'info' ) - demo() diff --git a/mininet-patch/examples/ns3/Ap-trace.pcap b/mininet-patch/examples/ns3/Ap-trace.pcap deleted file mode 100644 index 3cff6e013189f20d492bba8f14926e400b726183..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 9132 zcmcIqYitx%6uvX1Wmymw3VmQ}7cI!6z(NZYEM|RF8!fayijY7;NuXLFwh8zkB)T+M zBx$r!V~mn41j3`3P-^%A;n9jp)C6lpe*o4tBn4CmghVvauIKEzvvcn3Oow)NCz*Zp z-aX%Uzw@1Y=g#!f`Hp?M7$J-!5)qtzs1wjBt&sBe8{3c^coOtZ2&Ktf31aA zQ7AxZ^@zZ@*^#wGq{Ck{@xDmwguiR(B-TfZfLDzEH)b&W9Y+3Xe8k0<0RHg{w)l{B z1OIQp=jx~#t(wW$S=6DP!IZMAUBvKX>X5GzSEmRw8J``fJVTvEz~}0yRdtrLv#3Ko zs}oSio!$I;4iQiLSFCqrl+kugGOl(o*o+vOYspLF*VN1SSKsbAw$yQN>W&E0v^s<{&ISROPy4w)QSCo@64{`3}a_o zC*3J!*PEVhs$;>YZ1*OB@4nhsobZ_VF%QwYKyyYS*>PX(R{=iH4k62;7Y8{zi#pWv zP6FztuUHRc@T7eNUgc9>WG!mSJ|brc>?+m6x<}Y0-fqSo10m{HF}f!*!1fLc zo*Zjp#$_Y|SNXN-nB6ep7rR8$ZI0RAaWOK$_6y~J>70cRIiqM6kOhsOvfvw<3NDQB zGHLB)%|->9hl`6Na5X^g>8Y6qm2u%@q?7@lZq>Ag2RElaMeELAO=ZZeiJE&26_s^!sZsO8E=U@6!1+N7}j z0C;dM)mr%Oz8y=_o5mATGyXDaS$E6GxJPW$!;?%cZ>D8HhKBCT%fN%PR5QNkKgQB_ zw^OZTyyXwn^7VR|ab1WVNnzPKpt4jmUZ3q1K^Qxpo><0dB(%G1HMERfDN`$|2|t1Z zvyboS^KB5%S(6JKtx4U#Qq)>QlLtaOk!#1E+(PkUPB7xJ>vDA*$o^}H$JwjC%bd*6 zEE%PqjaK%9qMd_y98JwkTb|dPeJz^@md`^n|xlA z6fNt32WP4J>kMaU>#tTt%T%#E?pIl=S{|9@tR?kSeR=dc`Z9a7)DrGW-TywEZTfO! z>F|7c5_mXk**Ax=wD?l8RJ81B$BaL)p@VEFNbxS-@l`t z-IAsG1k1XkWIIn>EZ7sQt*^lM_-7;4ZPz?J74%9?>7^EuZr(m5^=%T z-w`W!Kop_LJL1vL@bVVyFJn*ZVl_y)pmBG~8jK&Sv6FQk>l@t&8TYhK?tXEs?>X*% zvGpovXUPO{yrU`s&k_wKlELni;8-&gcIxQesyZwa4)~A>{b?8)WJ0Zt!+_;nIe&2` zh7!^fGLEj?4H+gA9hg=2u;)CnQPV8q<_Tk8@9c?O9}Ygw6Y^dF;;#XGu7r7=fURwu zouPz$zDzxRsuIi-$zXT)H_gTqOr1eI;eZdGs9p|315c=9)p`e0q6%7_<_U`9SCwF% z7%G#lJa(@(<_SJe^s1G>RClNZHYW}~Phi%61bprZvv#nxAfK_bc!GKcR3(zk?p5zd xa~8GW(~KQ-#5e9iI#[s3]<--wifi-bridge-->[s4]<---network-b--->[h2]" - - net = Mininet() - - info( '*** Adding controllers\n' ) - net.addController( 'c0', controller=RemoteController, ip=127.0.0.1, port=6633 ) - net.addController( 'c1', controller=RemoteController, ip=127.0.0.2, port=6633 ) - - info( '*** Adding hosts\n' ) - h1 = net.addHost( 'h1', ip='10.0.0.1' ) - h2 = net.addHost( 'h2', ip='10.0.0.2' ) - - info( '*** Adding switches\n' ) - s3 = net.addSwitch( 's3' ) - s4 = net.addSwitch( 's4' ) - - info( '*** Creating links\n' ) - Link( s3, h1 ) - WIFIBridgeLink( s3, s4 ) - Link( s4, h2 ) - - info( '*** Starting network\n') - net.start() - mininet.ns3.start() - - info( '*** Running CLI\n' ) - CLI( net ) - - info( '*** Stopping network' ) - mininet.ns3.stop() - mininet.ns3.clear() - net.stop() - -if __name__ == '__main__': - setLogLevel( 'info' ) - emptyNet() diff --git a/mininet-patch/examples/ns3/emptynet-wifi.py b/mininet-patch/examples/ns3/emptynet-wifi.py deleted file mode 100644 index c54da0d..0000000 --- a/mininet-patch/examples/ns3/emptynet-wifi.py +++ /dev/null @@ -1,53 +0,0 @@ -#!/usr/bin/python - -""" -This example shows how to create an empty Mininet object -(without a topology object) and add nodes to it manually. -""" - -from mininet.net import Mininet -from mininet.node import RemoteController -from mininet.cli import CLI -from mininet.log import setLogLevel, info - -import mininet.ns3 # line added -from mininet.ns3 import WIFIApStaLink # line added - -def emptyNet(): - - "Create an empty network and add nodes to it." - "[h1]<---wifi-network-a--->[s3]<---wifi-network-b--->[h2]" - " ^ ^ ^ ^ " - " Sta Ap Ap Sta " - - net = Mininet() - - info( '*** Adding controller\n' ) - net.addController( 'c0', controller=RemoteController, ip="127.0.0.1", port=6633 ) - - info( '*** Adding hosts\n' ) - h1 = net.addHost( 'h1', ip='10.0.0.1' ) - h2 = net.addHost( 'h2', ip='10.0.0.2' ) - - info( '*** Adding switch\n' ) - s3 = net.addSwitch( 's3' ) - - info( '*** Creating links\n' ) - WIFIApStaLink( s3, h1, ssid="wifi-network-a" ) # line modified - WIFIApStaLink( s3, h2, ssid="wifi-network-b" ) # line modified - - info( '*** Starting network\n') - net.start() - mininet.ns3.start() # line added - - info( '*** Running CLI\n' ) - CLI( net ) - - info( '*** Stopping network' ) - mininet.ns3.stop() - mininet.ns3.clear() # line added - net.stop() - -if __name__ == '__main__': - setLogLevel( 'info' ) - emptyNet() diff --git a/mininet-patch/examples/ns3/simple-link.py b/mininet-patch/examples/ns3/simple-link.py deleted file mode 100644 index 4e1ed68..0000000 --- a/mininet-patch/examples/ns3/simple-link.py +++ /dev/null @@ -1,37 +0,0 @@ -from mininet.net import Mininet -from mininet.node import Node, Switch -from mininet.link import Link, Intf -from mininet.log import setLogLevel, info -from mininet.cli import CLI - -import mininet.ns3 -from mininet.ns3 import SimpleLink - - -if __name__ == '__main__': - setLogLevel( 'info' ) - info( '*** ns-3 network demo\n' ) - net = Mininet() - - info( '*** Creating Network\n' ) - h0 = net.addHost( 'h0' ) - h1 = net.addHost( 'h1' ) - - link = SimpleLink( h0, h1 ) - - mininet.ns3.start() - - info( '*** Configuring hosts\n' ) - h0.setIP( '192.168.123.1/24' ) - h1.setIP( '192.168.123.2/24') - - info( '*** Network state:\n' ) - for node in h0, h1: - info( str( node ) + '\n' ) - - info( '*** Running test\n' ) - h0.cmdPrint( 'ping -c1 ' + h1.IP() ) - h1.cmdPrint( 'ping -c1 ' + h0.IP() ) - - #CLI(net) - diff --git a/mininet-patch/examples/ns3/simple-segment.py b/mininet-patch/examples/ns3/simple-segment.py deleted file mode 100644 index 2b64175..0000000 --- a/mininet-patch/examples/ns3/simple-segment.py +++ /dev/null @@ -1,45 +0,0 @@ -from mininet.net import Mininet -from mininet.node import Node, Switch -from mininet.link import Link, Intf -from mininet.log import setLogLevel, info -from mininet.cli import CLI - -import mininet.ns3 -from mininet.ns3 import SimpleSegment - - -if __name__ == '__main__': - setLogLevel( 'info' ) - info( '*** ns-3 network demo\n' ) - net = Mininet() - - info( '*** Creating Network\n' ) - h0 = net.addHost( 'h0' ) - h1 = net.addHost( 'h1' ) - h2 = net.addHost( 'h2' ) - simple = SimpleSegment() - - simple.add( h0 ) - simple.add( h1 ) - simple.add( h2 ) - - - - info( '*** Configuring hosts\n' ) - h0.setIP( '192.168.123.1/24' ) - h1.setIP( '192.168.123.2/24') - h2.setIP( '192.168.123.3/24') - - mininet.ns3.start() - - - info( '*** Network state:\n' ) - for node in h0, h1, h2: - info( str( node ) + '\n' ) - - info( '*** Running test\n' ) - h0.cmdPrint( 'ping -c1 ' + h1.IP() ) - h0.cmdPrint( 'ping -c1 ' + h2.IP() ) - - CLI(net) - diff --git a/mininet-patch/examples/ns3/start-stop.py b/mininet-patch/examples/ns3/start-stop.py deleted file mode 100644 index 676c9a2..0000000 --- a/mininet-patch/examples/ns3/start-stop.py +++ /dev/null @@ -1,6 +0,0 @@ -from mininet.net import Mininet -import mininet.ns3 - -mininet.ns3.start() -mininet.ns3.stop() -mininet.ns3.clear() diff --git a/mininet-patch/examples/ns3/tbintf.py b/mininet-patch/examples/ns3/tbintf.py deleted file mode 100644 index a56d664..0000000 --- a/mininet-patch/examples/ns3/tbintf.py +++ /dev/null @@ -1,72 +0,0 @@ -from mininet.net import Mininet -from mininet.node import Node, Switch -from mininet.link import Link, Intf -from mininet.log import setLogLevel, info -from mininet.cli import CLI - -import mininet.ns3 -from mininet.ns3 import TBIntf - -import ns.network - - -if __name__ == '__main__': - setLogLevel( 'info' ) - info( '*** ns-3 network demo\n' ) - net = Mininet() - - info( '*** Creating Network\n' ) - h0 = net.addHost( 'h0' ) - h1 = net.addHost( 'h1' ) - h2 = net.addHost( 'h2' ) - -# NS part ------------------------------------------------------ - - channel = ns.network.SimpleChannel() - - h0ns = ns.network.Node() - device0 = ns.network.SimpleNetDevice() - device0.SetChannel(channel) - h0ns.AddDevice(device0) - - h1ns = ns.network.Node() - device1 = ns.network.SimpleNetDevice() - device1.SetChannel(channel) - h1ns.AddDevice(device1) - - h2ns = ns.network.Node() - device2 = ns.network.SimpleNetDevice() - device2.SetChannel(channel) - h2ns.AddDevice(device2) - -# NS part END -------------------------------------------------- - - - - tb0 = TBIntf(name="tap0", node=h0, port=None, nsNode=h0ns, nsDevice=device0) - - tb1 = TBIntf("tap1", h1, nsNode=h1ns, nsDevice=device1) - - tb2 = TBIntf("tap2", h2) - tb2.nsNode = h2ns - tb2.nsDevice = device2 - - - info( '*** Configuring hosts\n' ) - h0.setIP( '192.168.123.1/24' ) - h1.setIP( '192.168.123.2/24') - h2.setIP( '192.168.123.3/24') - - mininet.ns3.start() - - - info( '*** Network state:\n' ) - for node in h0, h1, h2: - info( str( node ) + '\n' ) - - info( '*** Running test\n' ) - h0.cmdPrint( 'ping -c1 ' + h1.IP() ) - h0.cmdPrint( 'ping -c1 ' + h2.IP() ) - - - diff --git a/mininet-patch/examples/ns3/wifi-adhoc.py b/mininet-patch/examples/ns3/wifi-adhoc.py deleted file mode 100644 index 317690f..0000000 --- a/mininet-patch/examples/ns3/wifi-adhoc.py +++ /dev/null @@ -1,46 +0,0 @@ -from mininet.net import Mininet -from mininet.node import Node, Switch -from mininet.link import Link, Intf -from mininet.log import setLogLevel, info -from mininet.cli import CLI - -import mininet.ns3 -from mininet.ns3 import WIFISegment - - -if __name__ == '__main__': - setLogLevel( 'info' ) - info( '*** ns-3 network demo\n' ) - net = Mininet() - - info( '*** Creating Network\n' ) - h0 = net.addHost('h0') - h1 = net.addHost('h1') - h2 = net.addHost('h2') - - wifi = WIFISegment() - - wifi.add( h0 ) - wifi.add( h1 ) - wifi.add( h2 ) - - - - info( '*** Configuring hosts\n' ) - h0.setIP( '192.168.123.1/24' ) - h1.setIP( '192.168.123.2/24') - h2.setIP( '192.168.123.3/24') - - mininet.ns3.start() - - - info( '*** Network state:\n' ) - for node in h0, h1, h2: - info( str( node ) + '\n' ) - - info( '*** Running test\n' ) - h0.cmdPrint( 'ping -c1 ' + h1.IP() ) - h0.cmdPrint( 'ping -c1 ' + h2.IP() ) - - CLI(net) - diff --git a/mininet-patch/examples/ns3/wifi-ap-pcap.py b/mininet-patch/examples/ns3/wifi-ap-pcap.py deleted file mode 100644 index 7825463..0000000 --- a/mininet-patch/examples/ns3/wifi-ap-pcap.py +++ /dev/null @@ -1,46 +0,0 @@ -from mininet.net import Mininet -from mininet.node import Node, Switch -from mininet.link import Link, Intf -from mininet.log import setLogLevel, info -from mininet.cli import CLI - -import mininet.ns3 -from mininet.ns3 import WIFISegment - - -if __name__ == '__main__': - setLogLevel( 'info' ) - info( '*** ns-3 network demo\n' ) - net = Mininet() - - info( '*** Creating Network\n' ) - h0 = net.addHost( 'h0' ) - h1 = net.addHost( 'h1' ) - h2 = net.addHost( 'h2' ) - - wifi = WIFISegment() - - wifi.addAp( h0 ) - wifi.addSta( h1 ) - wifi.addSta( h2 ) - - wifi.phyhelper.EnablePcap( "Ap-trace.pcap", h0.nsNode.GetDevice( 0 ), True, True ); - - info( '*** Configuring hosts\n' ) - h0.setIP( '192.168.123.1/24' ) - h1.setIP( '192.168.123.2/24') - h2.setIP( '192.168.123.3/24') - - mininet.ns3.start() - - - info( '*** Network state:\n' ) - for node in h0, h1, h2: - info( str( node ) + '\n' ) - - info( '*** Running test\n' ) - h0.cmdPrint( 'ping -c1 ' + h1.IP() ) - h0.cmdPrint( 'ping -c1 ' + h2.IP() ) - - CLI(net) - diff --git a/mininet-patch/examples/ns3/wifi-ap.py b/mininet-patch/examples/ns3/wifi-ap.py deleted file mode 100644 index 3e4763a..0000000 --- a/mininet-patch/examples/ns3/wifi-ap.py +++ /dev/null @@ -1,46 +0,0 @@ -from mininet.net import Mininet -from mininet.node import Node, Switch -from mininet.link import Link, Intf -from mininet.log import setLogLevel, info -from mininet.cli import CLI - -import mininet.ns3 -from mininet.ns3 import WIFISegment - - -if __name__ == '__main__': - setLogLevel( 'info' ) - info( '*** ns-3 network demo\n' ) - net = Mininet() - - info( '*** Creating Network\n' ) - h0 = net.addHost( 'h0' ) - h1 = net.addHost( 'h1' ) - h2 = net.addHost( 'h2' ) - - wifi = WIFISegment() - - wifi.addAp( h0 ) - wifi.addSta( h1 ) - wifi.addSta( h2 ) - - - - info( '*** Configuring hosts\n' ) - h0.setIP( '192.168.123.1/24' ) - h1.setIP( '192.168.123.2/24') - h2.setIP( '192.168.123.3/24') - - mininet.ns3.start() - - - info( '*** Network state:\n' ) - for node in h0, h1, h2: - info( str( node ) + '\n' ) - - info( '*** Running test\n' ) - h0.cmdPrint( 'ping -c1 ' + h1.IP() ) - h0.cmdPrint( 'ping -c1 ' + h2.IP() ) - - CLI(net) - diff --git a/mininet-patch/examples/ns3/wifi-positions.py b/mininet-patch/examples/ns3/wifi-positions.py deleted file mode 100644 index 7c96c0c..0000000 --- a/mininet-patch/examples/ns3/wifi-positions.py +++ /dev/null @@ -1,64 +0,0 @@ -from mininet.net import Mininet -from mininet.node import Node, Switch -from mininet.link import Link, Intf -from mininet.log import setLogLevel, info -from mininet.cli import CLI - -import mininet.ns3 -from mininet.ns3 import WIFISegment - - -if __name__ == '__main__': - setLogLevel( 'info' ) - info( '*** ns-3 network demo\n' ) - net = Mininet() - - info( '*** Creating Network\n' ) - h0 = net.addHost( 'h0' ) - h1 = net.addHost( 'h1' ) - wifi = WIFISegment() - - wifi.add( h0 ) - wifi.add( h1 ) - - - - info( '*** Configuring hosts\n' ) - h0.setIP( '192.168.123.1/24' ) - h1.setIP( '192.168.123.2/24') - - mininet.ns3.start() - - - info( '*** Testing network connectivity\n' ) - net.pingAll() - - info( '*** Nodes positions: \n' ) - info( 'h0:', mininet.ns3.getPosition( h0 ), '\n' ) - info( 'h1:', mininet.ns3.getPosition( h1 ), '\n' ) - - info( 'Testing bandwidth between h0 and h1 while 0 meters away\n' ) - net.iperf( ( h0, h1 ) ) - - info( '*** Changing h1 position: \n' ) - mininet.ns3.setPosition( h1 , 46.0, 38.0, 0.0) - - info( '*** Nodes positions: \n' ) - info( 'h0:', mininet.ns3.getPosition( h0 ), '\n' ) - info( 'h1:', mininet.ns3.getPosition( h1 ), '\n' ) - - info( 'Testing bandwidth between h0 and h1 while 60 meters away\n' ) - net.iperf( ( h0, h1 ) ) - - info( '*** Changing h1 position: \n' ) - mininet.ns3.setPosition( h1 , 68.0, 72.0, 0.0) - - info( '*** Nodes positions: \n' ) - info( 'h0:', mininet.ns3.getPosition( h0 ), '\n' ) - info( 'h1:', mininet.ns3.getPosition( h1 ), '\n' ) - - info( 'Testing bandwidth between h0 and h1 while 100 meters away\n' ) - net.iperf( ( h0, h1 ) ) - - - diff --git a/mininet-patch/examples/ns3/wifi-rate-anomaly.py b/mininet-patch/examples/ns3/wifi-rate-anomaly.py deleted file mode 100644 index 2e8e933..0000000 --- a/mininet-patch/examples/ns3/wifi-rate-anomaly.py +++ /dev/null @@ -1,68 +0,0 @@ -from mininet.net import Mininet -from mininet.node import Node, Switch -from mininet.link import Link, Intf -from mininet.log import setLogLevel, info -from mininet.cli import CLI - -import mininet.ns3 -from mininet.ns3 import WIFISegment - -import ns.core -import ns.wifi - - -if __name__ == '__main__': - setLogLevel( 'info' ) - info( '*** ns-3 network demo\n' ) - net = Mininet() - - info( '*** Creating Network\n' ) - h0 = net.addHost( 'h0' ) - h1 = net.addHost( 'h1' ) - h2 = net.addHost( 'h2' ) - - wifi = WIFISegment() - - - wifi.machelper.SetType ( "ns3::AdhocWifiMac" ) - - # set datarate for node h0 - wifi.wifihelper.SetRemoteStationManager( "ns3::ConstantRateWifiManager", - "DataMode", ns.core.StringValue( "OfdmRate54Mbps" ) ) - wifi.add( h0 ) - - # set datarate for node h1 - wifi.wifihelper.SetRemoteStationManager( "ns3::ConstantRateWifiManager", - "DataMode", ns.core.StringValue( "OfdmRate6Mbps" ) ) - wifi.add( h1 ) - - # set datarate for node h2 - wifi.wifihelper.SetRemoteStationManager( "ns3::ConstantRateWifiManager", - "DataMode", ns.core.StringValue( "OfdmRate54Mbps" ) ) - wifi.add( h2 ) - - - - info( '*** Configuring hosts\n' ) - h0.setIP( '192.168.123.1/24' ) - h1.setIP( '192.168.123.2/24') - h2.setIP( '192.168.123.3/24') - - mininet.ns3.start() - - - info( '*** Testing network connectivity\n' ) - net.pingAll() - - info( '*** Starting TCP iperf server on h2\n' ) - h2.sendCmd( "iperf -s" ) - - info( '*** Testing bandwidth between h0 and h2 while h1 is not transmitting\n' ) - h0.cmdPrint( "iperf -c 192.168.123.3" ) - - info( '*** Testing bandwidth between h0 and h2 while h1 is transmitting at 6Mbps\n' ) - h1.sendCmd( "iperf -c 192.168.123.3" ) - h0.cmdPrint( "iperf -c 192.168.123.3" ) - - CLI(net) - diff --git a/mininet-patch/examples/opennet/ap-sta-switch-host.py b/mininet-patch/examples/opennet/ap-sta-switch-host.py deleted file mode 100644 index 536d835..0000000 --- a/mininet-patch/examples/opennet/ap-sta-switch-host.py +++ /dev/null @@ -1,71 +0,0 @@ -#!/usr/bin/python - -from mininet.net import Mininet -from mininet.node import Node, Switch, RemoteController -from mininet.link import Link, Intf -from mininet.log import setLogLevel, info -from mininet.cli import CLI - -import mininet.ns3 -from mininet.ns3 import WifiSegment - -import ns.core -import ns.network -import ns.wifi -import ns.csma -import ns.wimax -import ns.uan -import ns.netanim - -from mininet.opennet import * - -def main(): - - net = Mininet() - net.addController('c0', controller=RemoteController, ip="127.0.0.1", port=6633) - - wifi = WifiSegment() - - # About AP - ap0 = net.addAP('ap0') - mininet.ns3.setMobilityModel(ap0, None) - mininet.ns3.setPosition(ap0, 0, 0, 0) - wifi.addAp(ap0, channelNumber=6, ssid="opennet_ap") - - # Check mininet.node.AP - if isinstance(ap0, mininet.node.AP): - print("I'm a AP") - - # About Station - sta0 = net.addStation('sta0') - mininet.ns3.setMobilityModel(sta0, None) - mininet.ns3.setPosition(sta0, 0, 0, 0) - wifi.addSta(sta0, channelNumber=6, ssid="opennet_ap") - - #Check mininet.node.Station - if isinstance(sta0, mininet.node.Station): - print("I'm a station") - - print("APs list: {0}\nSTAs list: {1}\n".format(wifi.aps, wifi.stas)) - - # About OVSSwitch - s0 = net.addSwitch('s0') - - # About Host - h0 = net.addHost('h0', ip="1.1.1.1") - - # Ignore warning message: "defaultIntf: warning: h0 has no interfaces" - net.addLink(s0, h0) - - print("Switches list: {0}\nHosts list: {1}\n".format(net.switches, net.hosts)) - - mininet.ns3.start() - net.start() - - mininet.ns3.stop() - net.stop() - - -if __name__ == '__main__': - setLogLevel('info') - main() diff --git a/mininet-patch/examples/opennet/two-ap-one-sw.py b/mininet-patch/examples/opennet/two-ap-one-sw.py deleted file mode 100644 index ff3f2ab..0000000 --- a/mininet-patch/examples/opennet/two-ap-one-sw.py +++ /dev/null @@ -1,82 +0,0 @@ -#!/usr/bin/python - -""" -+---------+ +---------+ +---------+ -| NS3 | | Mininet | | NS3 | -| AP0 +-+ Switch +-+ AP1 | -+----+----+ +---------+ +----+----+ - | | -+----+----+ +----+----+ -| NS3 | | NS3 | -| Station| | Station| -+---------+ +---------+ -""" - - -from mininet.net import Mininet -from mininet.node import Node, Switch, RemoteController -from mininet.link import Link, Intf -from mininet.log import setLogLevel, info -from mininet.cli import CLI - -import mininet.ns3 -from mininet.ns3 import WifiSegment - -import ns.core -import ns.network -import ns.wifi -import ns.csma -import ns.wimax -import ns.uan -import ns.netanim - -from mininet.opennet import * - -def main(): - - net = Mininet() - net.addController('c0', controller=RemoteController, ip="127.0.0.1", port=6633) - - sw0 = net.addSwitch('sw0', ip=None) - - ap0 = net.addAP('ap0', ip=None) - mininet.ns3.setMobilityModel(ap0, None) - mininet.ns3.setPosition(ap0, 0, 0, 0) - - ap1 = net.addAP('ap1', ip=None) - mininet.ns3.setMobilityModel(ap1, None) - mininet.ns3.setPosition(ap1, 10, 10, 0) - - sta0 = net.addStation('sta0', ip="10.0.0.1") - mininet.ns3.setMobilityModel(sta0, None) - mininet.ns3.setVelocity(sta0, 0, 5, 0) - - sta1 = net.addStation('sta1', ip="10.0.0.2") - mininet.ns3.setMobilityModel(sta1, None) - mininet.ns3.setVelocity(sta1, 5, 0, 0) - - wifi = WifiSegment(standard=ns.wifi.WIFI_PHY_STANDARD_80211g) - wifi.addAp(ap0, channelNumber=11, ssid="opennet_0") - wifi.addAp(ap1, channelNumber=11, ssid="opennet_1") - - wifi.addSta(sta0, channelNumber=11, ssid="opennet_0") - wifi.addSta(sta1, channelNumber=11, ssid="opennet_1") - - net.addLink(sw0, ap0) - net.addLink(sw0, ap1) - - net.start() - mininet.ns3.start() - - sta0.cmdPrint('ping -c2 ' + sta1.IP()) - sta1.cmdPrint('ping -c2 ' + sta0.IP()) - - CLI(net) - - mininet.ns3.stop() - mininet.ns3.clear() - net.stop() - -if __name__ == '__main__': - setLogLevel('info') - main() diff --git a/mininet-patch/examples/opennet/wifiroaming.py b/mininet-patch/examples/opennet/wifiroaming.py deleted file mode 100644 index 69eea87..0000000 --- a/mininet-patch/examples/opennet/wifiroaming.py +++ /dev/null @@ -1,208 +0,0 @@ -#!/usr/bin/python - -""" -This example shows how to create an empty Mininet object -(without a topology object) and add nodes to it manually. -""" -import sys -import os - -import mininet.net -import mininet.node -import mininet.cli -import mininet.log -import mininet.ns3 - -from mininet.net import Mininet, MininetWithControlNet -from mininet.node import Controller, RemoteController -from mininet.cli import CLI -from mininet.log import setLogLevel, info -from mininet.ns3 import * - -import ns.core -import ns.network -import ns.wifi -import ns.csma -import ns.wimax -import ns.uan -import ns.netanim - -from mininet.opennet import * - -""" -nodes is a list of node descriptions, each description contains several node attributes. - -name: The node identifier. -type: The character of this node, can be host or switch. - -position: The position of this node. -velocity: The velocity of this node, which will be used in host mobility model. - The default mobility model is ns3::ConstantVelocityMobilityModel. - -mobility: The mobility model of this node. setListPoritionAllocate() will take two parameters, - MobilityHelper and ListPositionAllocate. After install the PositionAllocate in the - MobilityHelper, setListoritionAllocate() will return the MobilityHelper. -""" - -nodes = [ { 'name': 'h1', 'type': 'host', 'ip': '10.10.10.1', 'position': (0.0, 10.0, 0.0), 'velocity': (2.5, 0, 0) }, - { 'name': 'h2', 'type': 'host', 'ip': '10.10.10.2', 'mobility': setListPositionAllocate( - createMobilityHelper("ns3::RandomWalk2dMobilityModel",n0="Bounds", - v0=ns.mobility.RectangleValue(ns.mobility.Rectangle(100,200,-50,50))), - createListPositionAllocate(x1=150,y1=30,z1=0)) }, - { 'name': 's1', 'type': 'switch', 'position': (0.0, 0.0, 0.0) }, - { 'name': 's2', 'type': 'switch', 'position': (120.0, 0.0, 0.0) }, - { 'name': 's3', 'type': 'switch', 'position': (60.0, 60.0*(3**0.5), 0.0) }, - { 'name': 's4', 'type': 'switch', 'position': (60.0, -60.0*(3**0.5), 0.0) }, - { 'name': 's5', 'type': 'switch', 'position': (-120.0, 0.0, 0.0) }, - { 'name': 's6', 'type': 'switch', 'position': (-60.0, 60.0*(3**0.5), 0.0) }, - { 'name': 's7', 'type': 'switch', 'position': (-60.0, -60.0*(3**0.5), 0.0) }, - ] - -""" -wifiintfs is a list of wifi interface descriptions, each description contains some wifi attributes. -""" - -wifiintfs = [ {'nodename': 'h1', 'type': 'sta', 'channel': 1, 'ssid': 'ssid'}, - {'nodename': 'h2', 'type': 'sta', 'channel': 11, 'ssid': 'ssid'}, - {'nodename': 's1', 'type': 'ap', 'channel': 1, 'ssid': 'ssid'}, - {'nodename': 's2', 'type': 'ap', 'channel': 6, 'ssid': 'ssid'}, - {'nodename': 's3', 'type': 'ap', 'channel': 11, 'ssid': 'ssid'}, - {'nodename': 's4', 'type': 'ap', 'channel': 11, 'ssid': 'ssid'}, - {'nodename': 's5', 'type': 'ap', 'channel': 6, 'ssid': 'ssid'}, - {'nodename': 's6', 'type': 'ap', 'channel': 11, 'ssid': 'ssid'}, - {'nodename': 's7', 'type': 'ap', 'channel': 11, 'ssid': 'ssid'}, - ] - -""" -links is a list of Ethernet links. -""" - -links = [ {'nodename1': 's1', 'nodename2': 's2'}, - {'nodename1': 's1', 'nodename2': 's3'}, - {'nodename1': 's1', 'nodename2': 's4'}, - {'nodename1': 's1', 'nodename2': 's5'}, - {'nodename1': 's1', 'nodename2': 's6'}, - {'nodename1': 's1', 'nodename2': 's7'}, - ] - -def WifiNet(): - - """ Create an Wifi network and add nodes to it. """ - - net = Mininet() - - info( '*** Adding controller\n' ) - net.addController( 'c0', controller=RemoteController, ip='127.0.0.1', port=6633 ) - - """ Initialize the WifiSegment, please refer ns3.py """ - wifi = WifiSegment(standard = ns.wifi.WIFI_PHY_STANDARD_80211g) - wifinodes = [] - - """ Initialize nodes """ - for n in nodes: - - """ Get attributes """ - nodename = n.get('name', None) - nodetype = n.get('type', None) - nodemob = n.get('mobility', None) - nodepos = n.get('position', None) - nodevel = n.get('velocity', None) - nodeip = n.get('ip', None) - - """ Assign the addfunc, please refer Mininet for more details about addHost and addSwitch """ - if nodetype is 'host': - addfunc = net.addHost - elif nodetype is 'switch': - addfunc = net.addSwitch - else: - addfunc = None - if nodename is None or addfunc is None: - continue - - """ Add the node into Mininet """ - node = addfunc (nodename, ip=nodeip) - - """ Set the mobility model """ - mininet.ns3.setMobilityModel (node, nodemob) - if nodepos is not None: - mininet.ns3.setPosition (node, nodepos[0], nodepos[1], nodepos[2]) - if nodevel is not None: - mininet.ns3.setVelocity (node, nodevel[0], nodevel[1], nodevel[2]) - - """ Append the node into wifinodes """ - wifinodes.append (node) - - """ Initialize Wifi Interfaces """ - for wi in wifiintfs: - - """ Get attributes """ - winodename = wi.get('nodename', None) - witype = wi.get('type', None) - wichannel = wi.get('channel', None) - wissid = wi.get('ssid', None) - - """ Assign the addfunc, please refer the WifiSegment in ns3.py """ - if witype is 'sta': - addfunc = wifi.addSta - elif witype is 'ap': - addfunc = wifi.addAp - else: - addfunc = None - if winodename is None or addfunc is None or wichannel is None: - continue - - """ Get wifi node and add it to the TapBridge """ - node = getWifiNode (wifinodes, winodename) - addfunc (node, wichannel, wissid) - - """ Initialize Ehternet links between switches """ - for cl in links: - clnodename1 = cl.get('nodename1', None) - clnodename2 = cl.get('nodename2', None) - if clnodename1 is None or clnodename2 is None: - continue - clnode1 = getWifiNode (wifinodes, clnodename1) - clnode2 = getWifiNode (wifinodes, clnodename2) - if clnode1 is None or clnode2 is None: - continue - net.addLink( clnode1, clnode2 ) - - """ Enable Pcap output""" - pcap = Pcap() - pcap.enable() - print pcap - - """ Enable netanim output""" - anim = Netanim("/tmp/xml/wifi-wired-bridged4.xml", nodes) - print anim - - """ Update node descriptions in the netanim """ - for node in wifinodes: - anim.UpdateNodeDescription (node.nsNode, str(node) + '-' + str(node.nsNode.GetId())) - if isinstance(node, mininet.node.OVSSwitch): - color = (0, 255, 0) - elif isinstance(node, mininet.node.Host): - color = (0, 0, 255) - anim.UpdateNodeColor (node.nsNode, color[0], color[1], color[2]) - - """ Start the simulation """ - info( '*** Starting network\n' ) - net.start() - mininet.ns3.start() - - info( 'Testing network connectivity\n' ) - wifinodes[0].cmdPrint( 'ping 10.10.10.2 -c 3' ) - - CLI( net ) - - info( '*** Stopping network\n' ) - mininet.ns3.stop() - info( '*** mininet.ns3.stop()\n' ) - mininet.ns3.clear() - info( '*** mininet.ns3.clear()\n' ) - net.stop() - info( '*** net.stop()\n' ) - -if __name__ == '__main__': - setLogLevel( 'info' ) - WifiNet() diff --git a/mininet-patch/mininet/ns3.py b/mininet-patch/mininet/ns3.py deleted file mode 100644 index 6da127e..0000000 --- a/mininet-patch/mininet/ns3.py +++ /dev/null @@ -1,944 +0,0 @@ -""" -From https://github.com/piotrjurkiewicz/mininet.git -Credit: Piotr Jurkiewicz -""" -""" - -NS-3 integration for Mininet. - - Mininet Mininet - node 1 node 2 -+---------+ +---------+ -| name | | name | -| space 1 | | space 2 | -| ------- | |---------| -| shell | | shell | -| ------- | |---------| -| Linux | | Linux | -| network | | network | -| stack | ns-3 ns-3 | stack | -| ------ | node 1 node 2 |---------| -| TAP | |===========| |===========| | TAP | -| intf. |<-fd->| TapBridge | | TapBridge |<-fd->| intf. | -+---------+ | --------- | | --------- | +---------+ - | ns-3 | | ns-3 | - | net | | net | - | device | | device | - +-----------+ +-----------+ - || || - +---------------------------+ - | ns-3 channel | - +---------------------------+ - |<------------------------------->| - ns-3 process - in the root namespace - -""" - -import threading, time, random - -from mininet.log import info, error, warn, debug -from mininet.link import Intf, Link -from mininet.node import Switch, Node -from mininet.util import quietRun, moveIntf, errRun - -import ns.core -import ns.network -import ns.tap_bridge -import ns.csma -import ns.wifi -import ns.mobility - -# Default duration of ns-3 simulation thread. You can freely modify this value. - -default_duration = 3600 - -# Set ns-3 simulator type to realtime simulator implementation. -# You can find more information about realtime modes here: -# http://www.nsnam.org/docs/release/3.17/manual/singlehtml/index.html#realtime -# http://www.nsnam.org/wiki/index.php/Emulation_and_Realtime_Scheduler - -ns.core.GlobalValue.Bind( "SimulatorImplementationType", ns.core.StringValue( "ns3::RealtimeSimulatorImpl" ) ) - -# Enable checksum computation in ns-3 devices. By default ns-3 does not compute checksums - it is not needed -# when it runs in simulation mode. However, when it runs in emulation mode and exchanges packets with the real -# world, bit errors may occur in the real world, so we need to enable checksum computation. - -ns.core.GlobalValue.Bind( "ChecksumEnabled", ns.core.BooleanValue ( "true" ) ) - -# Arrays which track all created TBIntf objects and Mininet nodes which has assigned an underlying ns-3 node. - -allTBIntfs = [] -allNodes = [] - -# These four global functions below are used to control ns-3 simulator thread. They are global, because -# ns-3 has one global singleton simulator object. - -def start(): - """ Start the simulator thread in background. - It should be called after configuration of all ns-3 objects - (TBintfs, Segments and Links). - Attempt of adding an ns-3 object when simulator thread is - running may result in segfault. You should stop it first.""" - global thread - if 'thread' in globals() and thread.isAlive(): - warn( "NS-3 simulator thread already running." ) - return - # Install all TapBridge ns-3 devices not installed yet. - for intf in allTBIntfs: - if not intf.nsInstalled: - intf.nsInstall() - # Set up the simulator thread. - thread = threading.Thread( target = runthread ) - thread.daemon = True - # Start the simulator thread (this is where fork happens). - # FORK! - thread.start() - # FORK:PARENT - # Code below is executed in the parent thread. - # Move all tap interfaces not moved yet to the right namespace. - for intf in allTBIntfs: - if not intf.inRightNamespace: - intf.namespaceMove() - return - -def runthread(): - """ Method called in the simulator thread on its start. - Should not be called manually.""" - # FORK:CHILD - # Code below is executed in the simulator thread after the fork. - # Stop event must be scheduled before simulator start. Not scheduling it - # may lead leads to segfault. - ns.core.Simulator.Stop( ns.core.Seconds( default_duration ) ) - # Start simulator. Function below blocks the Python thread and returns when simulator stops. - ns.core.Simulator.Run() - -def stop(): - """ Stop the simulator thread now.""" - # Schedule a stop event. - ns.core.Simulator.Stop( ns.core.MilliSeconds( 1 ) ) - # Wait until the simulator thread stops. - while thread.isAlive(): - time.sleep( 0.01 ) - return - -def clear(): - """ Clear ns-3 simulator. - It should be called when simulator is stopped.""" - ns.core.Simulator.Destroy() - for intf in allTBIntfs: - intf.nsInstalled = False - #intf.delete() - for node in allNodes: - del node.nsNode - del allTBIntfs[:] - del allNodes[:] - return - -def createAttributes( n0="", v0=ns.core.EmptyAttributeValue(), - n1="", v1=ns.core.EmptyAttributeValue(), - n2="", v2=ns.core.EmptyAttributeValue(), - n3="", v3=ns.core.EmptyAttributeValue(), - n4="", v4=ns.core.EmptyAttributeValue(), - n5="", v5=ns.core.EmptyAttributeValue(), - n6="", v6=ns.core.EmptyAttributeValue(), - n7="", v7=ns.core.EmptyAttributeValue()): - attrs = { 'n0' : n0, 'v0' : v0, - 'n1' : n1, 'v1' : v1, - 'n2' : n2, 'v2' : v2, - 'n3' : n3, 'v3' : v3, - 'n4' : n4, 'v4' : v4, - 'n5' : n5, 'v5' : v5, - 'n6' : n6, 'v6' : v6, - 'n7' : n7, 'v7' : v7 } - return attrs - -def setAttributes( func, typeStr, attrs): - a = { 'n0' : "", 'v0' : ns.core.EmptyAttributeValue(), - 'n1' : "", 'v1' : ns.core.EmptyAttributeValue(), - 'n2' : "", 'v2' : ns.core.EmptyAttributeValue(), - 'n3' : "", 'v3' : ns.core.EmptyAttributeValue(), - 'n4' : "", 'v4' : ns.core.EmptyAttributeValue(), - 'n5' : "", 'v5' : ns.core.EmptyAttributeValue(), - 'n6' : "", 'v6' : ns.core.EmptyAttributeValue(), - 'n7' : "", 'v7' : ns.core.EmptyAttributeValue() } - a.update (attrs) - func (typeStr, a['n0'], a['v0'], a['n1'], a['v1'], - a['n2'], a['v2'], a['n3'], a['v3'], - a['n4'], a['v4'], a['n5'], a['v5'], - a['n6'], a['v6'], a['n7'], a['v7']) - -def createMobilityHelper( mobilityType = "ns3::ConstantVelocityMobilityModel", **attrs): - mobHelper = ns.mobility.MobilityHelper() - setAttributes (mobHelper.SetMobilityModel, mobilityType, attrs) - return mobHelper - -def setPositionAllocate( mobHelper, posAllocateType = "ns3::RandomDiscPositionAllocator", **attrs): - setAttributes (mobHelper.SetPositionAllocator, posAllocateType, attrs) - return mobHelper - -def setListPositionAllocate( mobHelper, lpa): - mobHelper.SetPositionAllocator(lpa) - return mobHelper - -def createListPositionAllocate(**attrs): - lpa = ns.mobility.ListPositionAllocator() - i = 1 - while True: - if not attrs.has_key ('x'+ str(i)) and not attrs.has_key ('y'+ str(i)) and not attrs.has_key ('z'+ str(i)): - break - x = attrs.get('x'+ str(i), 0) - y = attrs.get('y'+ str(i), 0) - z = attrs.get('z'+ str(i), 0) - lpa.Add(ns.core.Vector(x, y, z)) - i = i+1 - return lpa - -def hasMobilityModel( node ): - if hasattr( node, 'nsNode' ) and node.nsNode is not None: - pass - else: - node.nsNode = ns.network.Node() - allNodes.append( node ) - try: - mm = node.nsNode.GetObject(ns.mobility.MobilityModel.GetTypeId()) - return ( mm is not None ) - except AttributeError: - warn("ns-3 mobility model not found\n") - return False - -def getMobilityModel( node ): - ''' Return the mobility model of a node - ''' - if hasattr( node, 'nsNode' ) and node.nsNode is not None: - pass - else: - node.nsNode = ns.network.Node() - allNodes.append( node ) - try: - mm = node.nsNode.GetObject(ns.mobility.MobilityModel.GetTypeId()) - return mm - except AttributeError: - warn("ns-3 mobility model not found\n") - return None - -def setMobilityModel( node, mobHelper = None): - ''' Set the mobility model of a node - ''' - if hasattr( node, 'nsNode' ) and node.nsNode is not None: - pass - else: - node.nsNode = ns.network.Node() - allNodes.append( node ) - if mobHelper is None: - mobHelper = createMobilityHelper () - mobHelper.Install (node.nsNode) - -# Functions for manipulating nodes positions. Nodes positioning is useful in -# wireless channel simulations: distance between nodes affects received signal power -# and, thus, throughput. -# Node positions are stored in the underlying ns-3 node (not in Mininet node itself). - -def getPosition( node ): - """ Return the ns-3 (x, y, z) position of a Mininet node. - Coordinates are in the 3D Cartesian system. - The unit is meters. - node: Mininet node""" - # Check if this Mininet node has assigned the underlying ns-3 node. - if hasattr( node, 'nsNode' ) and node.nsNode is not None: - # If it is assigned, go ahead. - pass - else: - # If not, create new ns-3 node and assign it to this Mininet node. - node.nsNode = ns.network.Node() - allNodes.append( node ) - try: - # Get postion coordinates from the ns-3 node - mm = node.nsNode.GetObject( ns.mobility.MobilityModel.GetTypeId() ) - pos = mm.GetPosition() - return ( pos.x, pos.y, pos.z ) - except AttributeError: - warn( "ns-3 mobility model not found\n" ) - return ( 0, 0, 0 ) - -def setPosition( node, x, y, z ): - """ Set the ns-3 (x, y, z) position of a Mininet node. - Coordinates are in the 3D Cartesian system. - The unit is meters. - node: Mininet node - x: integer or float x coordinate - y: integer or float y coordinate - z: integer or float z coordinate""" - # Check if this Mininet node has assigned the underlying ns-3 node. - if hasattr( node, 'nsNode' ) and node.nsNode is not None: - # If it is assigned, go ahead. - pass - else: - # If not, create new ns-3 node and assign it to this Mininet node. - node.nsNode = ns.network.Node() - allNodes.append( node ) - try: - mm = node.nsNode.GetObject( ns.mobility.MobilityModel.GetTypeId() ) - if x is None: - x = 0.0 - if y is None: - y = 0.0 - if z is None: - z = 0.0 - # Set postion coordinates in the ns-3 node - pos = mm.SetPosition( ns.core.Vector( x, y, z ) ) - except AttributeError: - warn( "ns-3 mobility model not found, not setting position\n" ) - -def getVelocity( node ): - ''' Return the ns-3 (x, y, z) velocity of a node. - ''' - if hasattr( node, 'nsNode' ) and node.nsNode is not None: - pass - else: - node.nsNode = ns.network.Node() - allNodes.append( node ) - try: - mm = node.nsNode.GetObject(ns.mobility.ConstantVelocityMobilityModel.GetTypeId()) - vel = mm.GetVelocity() - return (vel.x, vel.y, vel.z) - except AttributeError: - warn("ns-3 constant velocity mobility model not found\n") - return (0,0,0) - -def setVelocity( node, x = None, y = None, z = None ): - ''' Set the ns-3 (x, y, z) velocity of a node. - ''' - if hasattr( node, 'nsNode' ) and node.nsNode is not None: - pass - else: - node.nsNode = ns.network.Node() - allNodes.append( node ) - try: - mm = node.nsNode.GetObject(ns.mobility.ConstantVelocityMobilityModel.GetTypeId()) - if x is None: - x = 0.0 - if y is None: - y = 0.0 - if z is None: - z = 0.0 - vel = mm.SetVelocity(ns.core.Vector(x, y, z)) - except AttributeError: - warn("ns-3 constant velocity mobility model not found, not setting position\n") - -# TBIntf is the main workhorse of the module. TBIntf is a tap Linux interface located on Mininet -# node, which is bridged with ns-3 device located on ns-3 node. - -class TBIntf( Intf ): - """ Interface object that is bridged with ns-3 emulated device. - This is a subclass of Mininet basic Inft object. """ - - def __init__( self, name, node, port=None, - nsNode=None, nsDevice=None, mode=None, **params ): - """name: interface name (e.g. h1-eth0) - node: owning Mininet node (where this intf most likely lives) - link: parent link if we're part of a link #TODO - nsNode: underlying ns-3 node - nsDevice: ns-3 device which the tap interface is bridged with - mode: mode of TapBridge ns-3 device (UseLocal or UseBridge) - other arguments are passed to config()""" - self.name = name - # Create a tap interface in the system, ns-3 TapBridge will connect to that interface later. - self.createTap() - # Set this Intf to be delayed move. This tells Mininet not to move the interface to the right - # namespace during Intf.__init__(). Therefore, the interface must be moved manually later. - # Actually, interfaces are moved right after the simulator thread start, in the start() global - # function. - self.delayedMove = True - # If this node is running in its own namespace... - if node.inNamespace: - # ...this interface is not yet in the right namespace (it is in the root namespace just after - # creation) and should be moved later. - self.inRightNamespace = False - else: - # ...interface should stay in the root namespace, so it is in right namespace now. - self.inRightNamespace = True - # Initialize parent Intf object. - Intf.__init__( self, name, node, port , **params) - allTBIntfs.append( self ) - self.nsNode = nsNode - self.nsDevice = nsDevice - self.mode = mode - self.params = params - self.nsInstalled = False - # Create TapBridge ns-3 device. - self.tapbridge = ns.tap_bridge.TapBridge() - # If ns-3 node and bridged ns-3 device are set and TapBridge mode is known... - if self.nsNode and self.nsDevice and ( self.mode or self.node ): - # ...call nsInstall(). - self.nsInstall() - - def createTap( self ): - """Create tap Linux interface in the root namespace.""" - quietRun( 'ip tuntap add ' + self.name + ' mode tap' ) - - def nsInstall( self ): - """Install TapBridge ns-3 device in the ns-3 simulator.""" - if not isinstance( self.nsNode, ns.network.Node ): - warn( "Cannot install TBIntf to ns-3 Node: " - "nsNode not specified\n" ) - return - if not isinstance( self.nsDevice, ns.network.NetDevice ): - warn( "Cannot install TBIntf to ns-3 Node: " - "nsDevice not specified\n" ) - return - # If TapBridge mode has not been set explicitly, determine it automatically basing on - # a Mininet node type. You can find more about TapBridge modes there: - # http://www.nsnam.org/docs/release/3.18/models/singlehtml/index.html#tap-netdevice - if self.mode is None and self.node is not None: - # If Mininet node is some kind of Switch... - if isinstance( self.node, Switch ): - # ...use "UseBridge" mode. In this mode there may be many different L2 devices with - # many source addresses on the Linux side of TapBridge, but bridged ns-3 device must - # support SendFrom(). - self.mode = "UseBridge" - else: - # ...in the other case use "UseLocal" mode. In this mode there may be only one L2 source device - # on the Linux side of TapBridge (TapBridge will change source MAC address of all packets coming - # from the tap interface to the discovered address of this interface). In this mode bridged ns-3 - # device does not have to support SendFrom() (it uses Send() function to send packets). - self.mode = "UseLocal" - if self.mode is None: - warn( "Cannot install TBIntf to ns-3 Node: " - "cannot determine mode: neither mode nor (mininet) node specified\n" ) - return - # Set all required TapBridge attributes. - self.tapbridge.SetAttribute ( "Mode", ns.core.StringValue( self.mode ) ) - self.tapbridge.SetAttribute ( "DeviceName", ns.core.StringValue( self.name ) ) - self.tapbridge.SetAttributeFailSafe ( "Instant", ns.core.BooleanValue( True ) ) # to be implemented in ns-3 - # Add TapBridge device to the ns-3 node. - self.nsNode.AddDevice( self.tapbridge ) - # Set this TapBridge to be bridged with the specified ns-3 device. - self.tapbridge.SetBridgedNetDevice( self.nsDevice ) - # Installation is done. - self.nsInstalled = True - - def namespaceMove( self ): - """Move tap Linux interface to the right namespace.""" - loops = 0 - # Wait until ns-3 process connects to the tap Linux interface. ns-3 process resides in the root - # network namespace, so it must manage to connect to the interface before it is moved to the node - # namespace. After interface move ns-3 process will not see the interface. - while not self.isConnected(): - time.sleep( 0.01 ) - loops += 1 - if loops > 10: - warn( "Cannot move TBIntf to mininet Node namespace: " - "ns-3 has not connected yet to the TAP interface\n" ) - return - # Wait a little more, just for be sure ns-3 process not miss that. - time.sleep( 0.01 ) - # Move interface to the right namespace. - moveIntf( self.name, self.node ) - self.inRightNamespace = True - # IP address has been reset while moving to namespace, needs to be set again. - if self.ip is not None: - self.setIP( self.ip, self.prefixLen ) - # The same for 'up'. - self.isUp( True ) - - def isConnected( self ): - """Check if ns-3 TapBridge has connected to the Linux tap interface.""" - return self.tapbridge.IsLinkUp() - - def cmd( self, *args, **kwargs ): - "Run a command in our owning node namespace or in the root namespace when not yet inRightNamespace." - if self.inRightNamespace: - return self.node.cmd( *args, **kwargs ) - else: - cmd = ' '.join( [ str( c ) for c in args ] ) - return errRun( cmd )[ 0 ] - - def rename( self, newname ): - "Rename interface" - # If TapBridge is installed in ns-3, but ns-3 has not connected to the Linux tap interface yet... - if self.nsInstalled and not self.isConnected(): - # ...change device name in TapBridge to the new one. - self.tapbridge.SetAttribute ( "DeviceName", ns.core.StringValue( newname ) ) - Intf.rename( self, newname ) - - def delete( self ): - "Delete interface" - if self.nsInstalled: - warn( "You can not delete once installed ns-3 device, " - "run mininet.ns3.clear() to delete all ns-3 devices\n" ) - else: - Intf.delete( self ) - -# Network segment is a Mininet object consistng of ns-3 channel of a specific type. This can be seen as -# an equivalent of collision domain. Many Mininet nodes can be connected to the one network segment. -# During connecting, Mininet creates ns-3 device of particular type in the underlying ns-3 node. -# Then it connects this ns-3 device to the segment's ns-3 channel. Next, Mininet creates TBIntf in the -# specified Mininet node and bridges this tap interface with the ns-3 device created formerly. - -# Network link is a subclass of network segment. It is a network segment with only two nodes connected. -# Moreover, network link is a subclass of Mininet Link. It means that you can use it like standard Mininet -# Link and alternatively with it: it supports all methods of its superclass and constructor arguments order -# is the same. - -# SimpleChannel is the simplest channel model available in ns-3. Many devices can be connected to it -# simultaneously. Devices supports SendFrom(), therefore it can be used in "UseBridge" mode (for example -# for connecting switches). There is no implemented channel blocking - many devices can transmit -# simultaneously. Data rate and channel delay can not be set. However, one can -# set the receiver error model in SimpleNetDevice to simulate packet loss. You can find more information -# about the SimpleChannel in its source code and here: -# http://www.nsnam.org/docs/doxygen/classns3_1_1_simple_channel.html - -class SimpleSegment( object ): - """The simplest channel model available in ns-3. - SimpleNetDevice supports SendFrom().""" - def __init__( self ): - self.channel = ns.network.SimpleChannel() - - def add( self, node, port=None, intfName=None, mode=None ): - """Connect Mininet node to the segment. - node: Mininet node - port: node port number (optional) - intfName: node tap interface name (optional) - mode: TapBridge mode (UseLocal or UseBridge) (optional)""" - # Check if this Mininet node has assigned an underlying ns-3 node. - if hasattr( node, 'nsNode' ) and node.nsNode is not None: - # If it is assigned, go ahead. - pass - else: - # If not, create new ns-3 node and assign it to this Mininet node. - node.nsNode = ns.network.Node() - allNodes.append( node ) - # Create ns-3 device. - device = ns.network.SimpleNetDevice() - device.SetAddress (ns.network.Mac48Address.Allocate ()) - # Connect this device to the segment's channel. - device.SetChannel(self.channel) - # Add this device to the ns-3 node. - node.nsNode.AddDevice(device) - # If port number is not specified... - if port is None: - # ...obtain it automatically. - port = node.newPort() - # If interface name is not specified... - if intfName is None: - # ...obtain it automatically. - intfName = node.name + '-eth' + repr( port ) - # In the specified Mininet node, create TBIntf bridged with the 'device'. - tb = TBIntf( intfName, node, port, node.nsNode, device, mode ) - return tb - - -class SimpleLink( SimpleSegment, Link ): - """Link between two nodes using the SimpleChannel ns-3 model""" - def __init__( self, node1, node2, port1=None, port2=None, - intfName1=None, intfName2=None ): - """Create simple link to another node, making two new tap interfaces. - node1: first Mininet node - node2: second Mininet node - port1: node1 port number (optional) - port2: node2 port number (optional) - intfName1: node1 interface name (optional) - intfName2: node2 interface name (optional)""" - SimpleSegment.__init__( self ) - intf1 = SimpleSegment.add( self, node1, port1, intfName1 ) - intf2 = SimpleSegment.add( self, node2, port2, intfName2 ) - intf1.link = self - intf2.link = self - self.intf1, self.intf2 = intf1, intf2 - -# CsmaChannel is a more advanced model, built up upon SimpleChannel model. CsmaChannel is an equivalent -# of Ethernet channel, with CSMA blocking during transmission. Moreover, data rate and channel delay can -# be set (notice: setting high delay can result in low data rate, as channel is considered blocked for the -# trasmission of next packet for the delay interval after transmission start). -# You can find more information about CsmaChannel and CsmaNetDevice here: -# http://www.nsnam.org/docs/release/3.18/models/singlehtml/index.html#document-csma - -class CSMASegment( object ): - """Equivalent of the Ethernet channel - CsmaNetDevice supports SendFrom()""" - def __init__( self, DataRate=None, Delay=None ): - """DataRate: forced data rate of connected devices (optional), for example: 10Mbps, default: no-limit - Delay: channel trasmission delay (optional), for example: 10ns, default: 0""" - self.channel = ns.csma.CsmaChannel() - if DataRate is not None: - self.channel.SetAttribute( "DataRate", ns.network.DataRateValue( ns.network.DataRate( DataRate ) ) ) - if Delay is not None: - self.channel.SetAttribute( "Delay", ns.core.TimeValue( ns.core.Time( Delay ) ) ) - - def add( self, node, port=None, intfName=None, mode=None ): - """Connect Mininet node to the segment. - node: Mininet node - port: node port number (optional) - intfName: node tap interface name (optional) - mode: TapBridge mode (UseLocal or UseBridge) (optional)""" - # Check if this Mininet node has assigned an underlying ns-3 node. - if hasattr( node, 'nsNode' ) and node.nsNode is not None: - # If it is assigned, go ahead. - pass - else: - # If not, create new ns-3 node and assign it to this Mininet node. - node.nsNode = ns.network.Node() - allNodes.append( node ) - # Create ns-3 device. - device = ns.csma.CsmaNetDevice() - # Create queue used in the device. - queue = ns.network.DropTailQueue() - # Connect this device to the segment's channel. - device.Attach(self.channel) - # Set ns-3 device to use created queue. - device.SetQueue(queue) - device.SetAddress (ns.network.Mac48Address.Allocate ()) - # Add this device to the ns-3 node. - node.nsNode.AddDevice(device) - # If port number is not specified... - if port is None: - # ...obtain it automatically. - port = node.newPort() - # If interface name is not specified... - if intfName is None: - # ...obtain it automatically. - intfName = node.name + '-eth' + repr( port ) - # In the specified Mininet node, create TBIntf bridged with the 'device'. - tb = TBIntf( intfName, node, port, node.nsNode, device, mode ) - return tb - - -class CSMALink( CSMASegment, Link ): - """Link between two nodes using the CsmaChannel ns-3 model""" - def __init__( self, node1, node2, port1=None, port2=None, - intfName1=None, intfName2=None, DataRate=None, Delay=None ): - """Create Ethernet link to another node, making two new tap interfaces. - node1: first Mininet node - node2: second Mininet node - port1: node1 port number (optional) - port2: node2 port number (optional) - intfName1: node1 interface name (optional) - intfName2: node2 interface name (optional) - DataRate: forced data rate of connected devices (optional), for example: 10Mbps, default: no-limit - Delay: channel trasmission delay (optional), for example: 10ns, default: 0""" - CSMASegment.__init__( self, DataRate, Delay ) - intf1 = CSMASegment.add( self, node1, port1, intfName1 ) - intf2 = CSMASegment.add( self, node2, port2, intfName2 ) - intf1.link = self - intf2.link = self - self.intf1, self.intf2 = intf1, intf2 - -# Wifi model in ns-3 is much more complicated than wired models. Fortunatelly, there are many -# tutorials and examples of its usage in the net. Moreover, there is a large community of researchers -# and programmers around it. -# You can find more information about Wifi ns-3 model here: -# http://www.nsnam.org/docs/release/3.18/models/singlehtml/index.html#document-wifi - -# In order to facilitate its usage, it provides a series of helpers. Helpers are objects which provides -# fucntions used to create and set up of various components of Wifi model. - -class WIFISegment( object ): - """Equivalent of radio WiFi channel. - Only Ap and WDS devices support SendFrom().""" - def __init__( self ): - # Helpers instantiation. - self.channelhelper = ns.wifi.YansWifiChannelHelper.Default() - self.phyhelper = ns.wifi.YansWifiPhyHelper.Default() - self.wifihelper = ns.wifi.WifiHelper.Default() - self.machelper = ns.wifi.NqosWifiMacHelper.Default() - # Setting channel to phyhelper. - self.channel = self.channelhelper.Create() - self.phyhelper.SetChannel( self.channel ) - - def add( self, node, port=None, intfName=None, mode=None ): - """Connect Mininet node to the segment. - Will create WifiNetDevice with Mac type specified in - the MacHelper (default: AdhocWifiMac). - node: Mininet node - port: node port number (optional) - intfName: node tap interface name (optional) - mode: TapBridge mode (UseLocal or UseBridge) (optional)""" - # Check if this Mininet node has assigned an underlying ns-3 node. - if hasattr( node, 'nsNode' ) and node.nsNode is not None: - # If it is assigned, go ahead. - pass - else: - # If not, create new ns-3 node and assign it to this Mininet node. - node.nsNode = ns.network.Node() - allNodes.append( node ) - # Install new device to the ns-3 node, using provided helpers. - device = self.wifihelper.Install( self.phyhelper, self.machelper, node.nsNode ).Get( 0 ) - mobilityhelper = ns.mobility.MobilityHelper() - # Install mobility object to the ns-3 node. - mobilityhelper.Install( node.nsNode ) - # If port number is not specified... - if port is None: - # ...obtain it automatically. - port = node.newPort() - # If interface name is not specified... - if intfName is None: - # ...obtain it automatically. - intfName = node.name + '-eth' + repr( port ) - # In the specified Mininet node, create TBIntf bridged with the 'device'. - tb = TBIntf( intfName, node, port, node.nsNode, device, mode ) - return tb - - def addAdhoc( self, node, port=None, intfName=None, mode=None ): - """Connect Mininet node to the segment. - Will create WifiNetDevice with AdhocWifiMac. - Devices in that mode does not support SendFrom(). - node: Mininet node - port: node port number (optional) - intfName: node tap interface name (optional) - mode: TapBridge mode (UseLocal or UseBridge) (optional)""" - self.machelper.SetType ("ns3::AdhocWifiMac") - return self.add( node, port, intfName, mode ) - - def addAp( self, node, port=None, intfName=None, mode=None, ssid="default-ssid" ): - """Connect Mininet node to the segment. - Will create WifiNetDevice with ApWifiMac (access point). - Devices in that mode supports SendFrom() (can be used on switches). - node: Mininet node - port: node port number (optional) - intfName: node tap interface name (optional) - mode: TapBridge mode (UseLocal or UseBridge) (optional) - ssid: network SSID (optional)""" - self.machelper.SetType ("ns3::ApWifiMac", "Ssid", ns.wifi.SsidValue (ns.wifi.Ssid(ssid)), - "BeaconGeneration", ns.core.BooleanValue(True), - "BeaconInterval", ns.core.TimeValue(ns.core.Seconds(2.5))) - return self.add( node, port, intfName, mode ) - - def addSta( self, node, port=None, intfName=None, mode=None, ssid="default-ssid" ): - """Connect Mininet node to the segment. - Will create WifiNetDevice with StaWifiMac (client station). - Devices in that mode does not support SendFrom(). - node: Mininet node - port: node port number (optional) - intfName: node tap interface name (optional) - mode: TapBridge mode (UseLocal or UseBridge) (optional) - ssid: network SSID (optional)""" - self.machelper.SetType ("ns3::StaWifiMac", "Ssid", ns.wifi.SsidValue (ns.wifi.Ssid(ssid))) - return self.add( node, port, intfName, mode ) - - -class WIFIApStaLink( WIFISegment, Link ): - """Link between two nodes using infrastructure WiFi channel.""" - def __init__( self, node1, node2, port1=None, port2=None, - intfName1=None, intfName2=None, ssid="default-ssid" ): - """Create infractructure WiFi link to another node, making two new tap interfaces. - node1: first Mininet node (access point) - node2: second Mininet node (client station) - port1: node1 port number (optional) - port2: node2 port number (optional) - intfName1: node1 interface name (optional) - intfName2: node2 interface name (optional) - ssid: network SSID (optional)""" - WIFISegment.__init__( self ) - intf1 = WIFISegment.addAp( self, node1, port1, intfName1, ssid=ssid ) - intf2 = WIFISegment.addSta( self, node2, port2, intfName2, ssid=ssid ) - intf1.link = self - intf2.link = self - self.intf1, self.intf2 = intf1, intf2 - -class WifiSegment( object ): - def __init__( self, channelHelper = ns.wifi.YansWifiChannelHelper.Default(), - maxChannelNumber = 11, standard = ns.wifi.WIFI_PHY_STANDARD_80211a, - stationManager = "ns3::ArfWifiManager", **attrs): - self.wifiHelper = ns.wifi.WifiHelper.Default () - setAttributes (self.wifiHelper.SetRemoteStationManager, stationManager, attrs) - self.wifiHelper.SetStandard (standard) - self.channel = channelHelper.Create () - self.maxChannelNumber = maxChannelNumber - self.baseSsid = 'ssid' - self.aps = [] - self.stas = [] - - def __del__( self ): - for ap in self.aps: - del ap - for sta in self.stas: - del sta - del self.aps[:] - del self.stas[:] - - def add( self, node, phyHelper, macHelper, port=None, intfName=None ): - if phyHelper is None or macHelper is None: - warn( "phyHelper and macHelper must not be none.\n" ) - return None - if hasattr( node, 'nsNode' ) and node.nsNode is not None: - pass - else: - node.nsNode = ns.network.Node() - allNodes.append( node ) - phyHelper.SetChannel (channel = self.channel) - device = self.wifiHelper.Install (phyHelper, macHelper, node.nsNode).Get(0) - device.SetAddress (ns.network.Mac48Address.Allocate ()) - if port is None: - port = node.newPort() - if intfName is None: - intfName = node.name + '-eth' + repr( port ) - tb = TBIntf( intfName, node, port, node.nsNode, device) - return tb - - def addAp( self, node, channelNumber, ssid=None, enableQos=False, port=None, intfName=None, **attrs): - if ssid is None: - ssid = self.baseSsid + str(len (self.aps) + 1) - if channelNumber <= 0 or channelNumber > self.maxChannelNumber: - channelNumber = random.randint (1, self.maxChannelNumber) - warn("illegal channel number, choose a random channel number %s.\n", channelNumber) - phyHelper = ns.wifi.YansWifiPhyHelper().Default() - phyHelper.Set ("ChannelNumber", ns.core.UintegerValue(channelNumber)) - if enableQos: - macHelper = ns.wifi.QosWifiMacHelper.Default() - else: - macHelper = ns.wifi.NqosWifiMacHelper.Default() - - setAttributes (macHelper.SetType, "ns3::ApWifiMac", attrs) - tb = self.add (node, phyHelper, macHelper, port, intfName) - if type( ssid ) is str: - wifissid = ns.wifi.Ssid (ssid) - else: - wifissid = ssid - try: - tb.nsDevice.GetMac ().SetAttribute ("Ssid", ns.wifi.SsidValue (wifissid)) - except: - warn("the type of wifissid isn't ssidvalue.\n") - wifissid = ns.wifi.Ssid (self.baseSsid + str(len (self.aps) + 1)) - tb.nsDevice.GetMac ().SetAttribute ("Ssid", ns.wifi.SsidValue (wifissid)) - self.aps.append(tb) - return tb - - def addSta( self, node, channelNumber, ssid=None, enableQos=False, enableScan = True, port=None, intfName=None, **attrs): - if ssid is None: - ssid = "" - if channelNumber <= 0 or channelNumber > self.maxChannelNumber: - channelNumber = random.randint (1, self.maxChannelNumber) - warn("illegal channel number, choose a random channel number %s.\n", channelNumber) - phyHelper = ns.wifi.YansWifiPhyHelper().Default() - phyHelper.Set ("ChannelNumber", ns.core.UintegerValue(channelNumber)) - if enableQos: - macHelper = ns.wifi.QosWifiMacHelper.Default() - else: - macHelper = ns.wifi.NqosWifiMacHelper.Default() - setAttributes (macHelper.SetType, "ns3::StaWifiMac", attrs) - tb = self.add (node, phyHelper, macHelper, port, intfName) - if type( ssid ) is str: - wifissid = ns.wifi.Ssid (ssid) - else: - wifissid = ssid - try: - tb.nsDevice.GetMac ().SetAttribute ("Ssid", ns.wifi.SsidValue (wifissid)) - except: - warn("the type of wifissid isn't ssidvalue.\n") - tb.nsDevice.GetMac ().SetAttribute ("Ssid", ns.wifi.SsidValue ("")) - if enableScan: - tb.nsDevice.GetMac ().SetAttribute ("ScanType", ns.core.EnumValue (ns.wifi.StaWifiMac.ACTIVE)) - tb.nsDevice.GetMac ().SetAttribute ("MaxScanningChannelNumber", ns.core.UintegerValue(self.maxChannelNumber)) - else: - tb.nsDevice.GetMac ().SetAttribute ("ScanType", ns.core.EnumValue (ns.wifi.StaWifiMac.NOTSUPPORT)) - self.stas.append(tb) - return tb - - @staticmethod - def createChannelHelper(): - channelHelper = ns.wifi.YansWifiChannelHelper () - return channelHelper - - def addChannelPropagationLoss( channelHelper, propagationLossType, **attrs ): - setAttributes (channelHelper.AddPropagationLoss, propagationLossType, attrs) - return channelHelper - - def setChannelPropagationDelay( channelHelper, propagationDelayType, **attrs ): - setAttributes (channelHelper.AddPropagationLoss, propagationDelayType, attrs) - return channelHelper - -# WIFIBridgeLink uses WDSWifiMac mode, which (as for now) is not a part of ns-3 official release. You can add -# it to ns-3 using this patch: http://gist.github.com/piotrjurkiewicz/6483675 - -# With the infrastructure mode it is posiible to connect hosts (Sta devices) with switches (Ap devices). -# However, you can't connect two switches (two Distribution Systems). In order to do that, you must use all -# four address fields in 802.11 frame. Such mode is called WDS mode or 4-address mode (4A) or even bridge mode. - -class WIFIBridgeLink( WIFISegment, Link ): - """Link between two nodes using WDS WiFi channel. - This link bridges two distribution systems, so two - switches can be connected on the both sides of link.""" - def __init__( self, node1, node2, port1=None, port2=None, - intfName1=None, intfName2=None ): - """Create WDS bridge, making two new tap interfaces. - node1: first Mininet node - node2: second Mininet node - port1: node1 port number (optional) - port2: node2 port number (optional) - intfName1: node1 interface name (optional) - intfName2: node2 interface name (optional)""" - WIFISegment.__init__( self ) - # It this case the order of TBIntf and ns-3 device creation is reversed: - # TBIntfs (and thus tap interfaces) are created before ns-3 WifiNetDevices. - # Tap interfaces must be created earlier, becauses Mac addresses of the paired - # node must be provided when setting WDSWifiMac. - # NODE 1 - # Check if this Mininet node has assigned an underlying ns-3 node. - if hasattr( node1, 'nsNode' ) and node1.nsNode is not None: - # If it is assigned, go ahead. - pass - else: - # If not, create new ns-3 node and assign it to this Mininet node. - node1.nsNode = ns.network.Node() - allNodes.append( node1 ) - mobilityhelper1 = ns.mobility.MobilityHelper() - # Install mobility object to the ns-3 node. - mobilityhelper1.Install( node1.nsNode ) - # If port number is not specified... - if port1 is None: - # ...obtain it automatically. - port1 = node1.newPort() - # If interface name is not specified... - if intfName1 is None: - # ...obtain it automatically. - intfName1 = node1.name + '-eth' + repr( port1 ) - # ns-3 device is not specified in the following call, so nsInstall() will nor occur automatically. - tb1 = TBIntf( intfName1, node1, port1, node1.nsNode ) - # NODE 2 - # Check if this Mininet node has assigned an underlying ns-3 node. - if hasattr( node2, 'nsNode' ) and node2.nsNode is not None: - # If it is assigned, go ahead. - pass - else: - # If not, create new ns-3 node and assign it to this Mininet node. - node2.nsNode = ns.network.Node() - allNodes.append( node2 ) - mobilityhelper2 = ns.mobility.MobilityHelper() - # Install mobility object to the ns-3 node. - mobilityhelper2.Install( node2.nsNode ) - # If port number is not specified... - if port2 is None: - # ...obtain it automatically. - port2 = node2.newPort() - # If interface name is not specified... - if intfName2 is None: - # ...obtain it automatically. - intfName2 = node2.name + '-eth' + repr( port2 ) - # ns-3 device is not specified in the following call, so nsInstall() will nor occur automatically. - tb2 = TBIntf( intfName2, node2, port2, node2.nsNode ) - # NODE 1 - # Set Mac type and paired device Mac address for the node 1. - self.machelper.SetType ("ns3::WDSWifiMac", - "ReceiverAddress", ns.network.Mac48AddressValue( ns.network.Mac48Address( tb2.MAC() ) ) ) - # Create and install WifiNetDevice. - device1 = self.wifihelper.Install( self.phyhelper, self.machelper, node1.nsNode ).Get( 0 ) - # Set nsDevice in TapBridge the the created one. - tb1.nsDevice = device1 - # Install TapBridge to the ns-3 node. - tb1.nsInstall() - # NODE 2 - # Set Mac type and paired device Mac address for the node 2. - self.machelper.SetType ("ns3::WDSWifiMac", - "ReceiverAddress", ns.network.Mac48AddressValue( ns.network.Mac48Address( tb1.MAC() ) ) ) - # Create and install WifiNetDevice. - device2 = self.wifihelper.Install( self.phyhelper, self.machelper, node2.nsNode ).Get( 0 ) - # Set nsDevice in TapBridge the the created one. - tb2.nsDevice = device2 - # Install TapBridge to the ns-3 node. - tb2.nsInstall() - # - tb1.link = self - tb2.link = self - self.intf1, self.intf2 = tb1, tb2 - diff --git a/mininet-patch/mininet/opennet.py b/mininet-patch/mininet/opennet.py deleted file mode 100644 index 2f21149..0000000 --- a/mininet-patch/mininet/opennet.py +++ /dev/null @@ -1,99 +0,0 @@ -#!/usr/bin/python - -import os -import ns.netanim -import ns.csma -import ns.wifi - -def checkDictionaryPath(path): - """ Check dictionary exist or not, if not create it """ - if not os.path.exists(os.path.dirname(path)): - os.makedirs(os.path.dirname(path)) - return path - - -class Netanim( object ): - def __init__(self, path="/tmp/xml/wifi-wired-bridged4.xml", nodes=None, packetmetadata=True): - self.path = path - self.packetmetadata = packetmetadata - self.nodes = nodes - self.netanim = self.Netanim() - - def __str__(self): - return repr(self) - - def __repr__(self): - path_str = "Netanim path: %s" % self.getNetanimPath() - return path_str - - def Netanim(self): - """ Enable netanim output """ - checkDictionaryPath(self.path) - netanim = ns.netanim.AnimationInterface(self.path) - netanim.EnablePacketMetadata(self.packetmetadata) - return netanim - - def getNetanimPath(self): - return self.path - - def UpdateNodeDescription(self, node, desc): - self.netanim.UpdateNodeDescription(node, desc) - return True - - def UpdateNodeColor(self, node, r, g, b): - self.netanim.UpdateNodeColor(node, r, g, b) - return True - -class Pcap( object ): - def __init__(self, wifi_pcap_path="/tmp/pcap/wifi", csma_pcap_path="/tmp/pcap/csma"): - self.wifi_pcap_path = wifi_pcap_path - self.csma_pcap_path = csma_pcap_path - - def __str__(self): - return repr(self) - - def __repr__(self): - pcap_path = "Wifi pcap path: %s\nCSMA pcap path:%s" % (self.getWifiPath(), self.getCSMAPath()) - return pcap_path - - def setWifiPath(self, path): - checkDictionaryPath(path) - self.wifi_pcap_path = checkDictionaryPath(path) - return True - - def setCSMAPath(self, path): - checkDictionaryPath(path) - self.csma_pcap_path = path - return True - - def getWifiPath(self): - return self.wifi_pcap_path - - def getCSMAPath(self): - return self.csma_pcap_path - - def enable(self): - - """ Setting Wifi pcap """ - self.setWifiPath(self.wifi_pcap_path) - ns.wifi.YansWifiPhyHelper().Default().EnablePcapAll(self.wifi_pcap_path) - - """ Setting CSMA pcap """ - self.setCSMAPath(self.csma_pcap_path) - ns.csma.CsmaHelper().EnablePcapAll(self.csma_pcap_path) - - return True - -""" -getWifiNode will return the wifinode with specific name. -""" - -def getWifiNode( wifinode, name): - for n in wifinode: - if n.name == name: - return n - return None - -def addCSMALink(node1, node2, datarate="100Mbps"): - CSMALink(node1, node2, datarate) -