Skip to content

Commit 244e1b2

Browse files
committed
Merge pull request #75 from pichuang/master
Discard all AP/Station Class and add new nctu EC topology
2 parents 779e419 + 7430dbd commit 244e1b2

4 files changed

Lines changed: 175 additions & 8 deletions

File tree

ansible/roles/ns3/tasks/main.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@
4848
poll: 0
4949
ignore_errors: true
5050
tags: ns3
51+
- name: Waf install
52+
command: "./waf install"
53+
args:
54+
chdir: "{{ home_location }}/ns-allinone-{{ NS3_VERSION }}/ns-{{ NS3_VERSION }}"
55+
tags: ns3
56+
- name: Configure dynamic linker run-time bindings
57+
command: "ldconfig"
58+
tags: ns3
5159
- name: Create Waf Shell
5260
template:
5361
src: "waf_shell.sh.j2"
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
#!/usr/bin/python
2+
'''
3+
nctu_cs_wired_and_wireless_topo.gy
4+
'''
5+
6+
from mininet.cluster.net import MininetCluster
7+
from mininet.cluster.placer import DFSPlacer
8+
from mininet.log import setLogLevel
9+
from mininet.cluster.cli import ClusterCLI as CLI
10+
from mininet.node import Controller, RemoteController
11+
from mininet.topo import Topo
12+
from itertools import combinations
13+
import mininet.ns3
14+
from mininet.ns3 import WifiSegment
15+
16+
CONTROLLER_IP = "192.168.59.100"
17+
CONTROLLER_PORT = 6633
18+
19+
SERVER_LIST = [ 'mininet1', 'mininet2' ]
20+
21+
class NCTU_EC_Topology( Topo ):
22+
23+
def __init__(self, core=1, agg=6, access=6, host=5, *args, **kwargs):
24+
Topo.__init__(self, *args, **kwargs)
25+
self.core_num = core
26+
self.agg_num = agg
27+
self.access_num = access
28+
self.host_num = host
29+
self.sw_id = 1
30+
self.host_id = 1
31+
32+
# Init switch and host list
33+
self.core_sw_list = []
34+
self.agg_sw_list = []
35+
self.access_sw_list = []
36+
self.host_list = []
37+
38+
self.create_top_switch( "core", self.core_num, self.core_sw_list )
39+
40+
self.handle_top_down( "agg", self.agg_num, self.core_sw_list, self.agg_sw_list )
41+
self.handle_top_down( "access", self.access_num, self.agg_sw_list, self.access_sw_list )
42+
43+
self.handle_host( "h", self.host_num, self.host_list )
44+
45+
self.handle_mesh( self.agg_sw_list )
46+
47+
def create_top_switch( self, prefix_name, sw_num, sw_list):
48+
for i in xrange(1, sw_num+1):
49+
sw_list.append(self.addSwitch("{0}{1}".format(prefix_name, i), dpid='{0:x}'.format(self.sw_id)))
50+
self.sw_id += 1
51+
52+
def handle_top_down( self, prefix_name, num, top_list, down_list):
53+
temp = 0
54+
for i in xrange(0, len(top_list)):
55+
for j in xrange(1, num+1):
56+
switch = self.addSwitch("{0}{1}".format(prefix_name, j + temp), dpid='{0:x}'.format(self.sw_id))
57+
self.addLink(top_list[i], switch)
58+
down_list.append(switch)
59+
self.sw_id += 1
60+
temp = j
61+
62+
63+
def handle_host( self, prefix_name, host_num, host_list ):
64+
for i in xrange(0, len(self.access_sw_list)):
65+
for j in xrange(0, host_num):
66+
host = self.addHost('{0}{1}'.format(prefix_name, self.host_id))
67+
# Link to access sw
68+
self.addLink(self.access_sw_list[i], host)
69+
# Append host to list
70+
host_list.append(host)
71+
self.host_id += 1
72+
73+
def handle_mesh( self, sw_list ):
74+
for link in combinations(sw_list, 2):
75+
self.addLink(link[0], link[1])
76+
77+
78+
def RunTestBed():
79+
80+
# NCTU_EC_Topology( Core Switch, Aggregate Switch, Access Switch, Host)
81+
topo = NCTU_EC_Topology(core=1, agg=3, access=3, host=2)
82+
83+
net = MininetCluster( controller=RemoteController, topo=topo, servers=SERVER_LIST, placement=DFSPlacer, root_node="core1", tunneling="vxlan" )
84+
net.addController( 'controller', controller=RemoteController, ip=CONTROLLER_IP, port=CONTROLLER_PORT )
85+
86+
wifi = WifiSegment()
87+
88+
"""
89+
Create AP
90+
"""
91+
ap_to_access_sw = 0
92+
for i in xrange(1):
93+
AP_NAME = "ap" + str(i)
94+
ap = net.addSwitch(AP_NAME, server=SERVER_LIST[0])
95+
mininet.ns3.setMobilityModel(ap, None)
96+
mininet.ns3.setPosition(ap, 0, 0, 0)
97+
wifi.addAp(ap, channelNumber=6, ssid="opennet-ap", port=0)
98+
net.addLink(ap, topo.access_sw_list[ap_to_access_sw])
99+
ap_to_access_sw += 1
100+
101+
"""
102+
Create Station
103+
"""
104+
STA_NAME = "sta" + str(0)
105+
sta = net.addHost(STA_NAME, server=SERVER_LIST[0])
106+
mininet.ns3.setMobilityModel(sta, None)
107+
mininet.ns3.setPosition(sta, 0, 0, 0)
108+
wifi.addSta(sta, channelNumber=6, ssid="opennet-ap", port=0)
109+
110+
net.start()
111+
mininet.ns3.start()
112+
113+
"""
114+
Post Handle
115+
"""
116+
# XXX Need to fixed
117+
AP_NAME = "ap" + str(0)
118+
cmd = "ovs-vsctl add-port {0} {0}-eth0".format(AP_NAME)
119+
net.getNodeByName(AP_NAME).cmdPrint(cmd)
120+
121+
STA_NAME = "sta" + str(0)
122+
cmd = "ip addr add 10.0.0.{0}/8 dev {1}-eth0".format(str(200+i), STA_NAME)
123+
net.getNodeByName(STA_NAME).cmdPrint(cmd)
124+
net.getNodeByName(STA_NAME).cmdPrint("ip addr show dev {0}-eth0".format(STA_NAME))
125+
126+
"""
127+
Show interface object in ns3
128+
"""
129+
print("*** allTBintfs: {0}\n".format(mininet.ns3.allTBIntfs))
130+
CLI( net )
131+
mininet.ns3.stop()
132+
mininet.ns3.clear()
133+
net.stop()
134+
135+
if __name__ == '__main__':
136+
setLogLevel('info')
137+
RunTestBed()

mininet-patch/examples/opennet/ap-sta-switch-host.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,20 @@ def main():
2727
wifi = WifiSegment()
2828

2929
# About AP
30-
ap0 = net.addAP("ap0", wifi, channelNumber=6, ssid="opennet_ap", positions=(0, 0, 0))
30+
ap0 = net.addAP('ap0')
31+
mininet.ns3.setMobilityModel(ap0, None)
32+
mininet.ns3.setPosition(ap0, 0, 0, 0)
33+
wifi.addAp(ap0, channelNumber=6, ssid="opennet_ap")
3134

3235
# Check mininet.node.AP
3336
if isinstance(ap0, mininet.node.AP):
3437
print("I'm a AP")
3538

3639
# About Station
37-
sta0 = net.addStation("sta0", wifi, channelNumber=6, ssid="opennet_ap", positions=(0, 0, 0))
40+
sta0 = net.addStation('sta0')
41+
mininet.ns3.setMobilityModel(sta0, None)
42+
mininet.ns3.setPosition(sta0, 0, 0, 0)
43+
wifi.addSta(sta0, channelNumber=6, ssid="opennet_ap")
3844

3945
#Check mininet.node.Station
4046
if isinstance(sta0, mininet.node.Station):
@@ -55,7 +61,7 @@ def main():
5561

5662
mininet.ns3.start()
5763
net.start()
58-
CLI(net)
64+
5965
mininet.ns3.stop()
6066
net.stop()
6167

mininet-patch/examples/opennet/two-ap-one-sw.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,31 @@ def main():
3636

3737
net = Mininet()
3838
net.addController('c0', controller=RemoteController, ip="127.0.0.1", port=6633)
39-
wifi = WifiSegment(standard=ns.wifi.WIFI_PHY_STANDARD_80211g)
4039

4140
sw0 = net.addSwitch('sw0', ip=None)
4241

43-
ap0 = net.addAP('ap0', wifi, channelNumber=11, ssid="opennet_0", positions=(0, 0, 0))
44-
ap1 = net.addAP('ap1', wifi, channelNumber=11, ssid="opennet_1", positions=(10, 10, 0))
42+
ap0 = net.addAP('ap0', ip=None)
43+
mininet.ns3.setMobilityModel(ap0, None)
44+
mininet.ns3.setPosition(ap0, 0, 0, 0)
45+
46+
ap1 = net.addAP('ap1', ip=None)
47+
mininet.ns3.setMobilityModel(ap1, None)
48+
mininet.ns3.setPosition(ap1, 10, 10, 0)
49+
50+
sta0 = net.addStation('sta0', ip="10.0.0.1")
51+
mininet.ns3.setMobilityModel(sta0, None)
52+
mininet.ns3.setVelocity(sta0, 0, 5, 0)
53+
54+
sta1 = net.addStation('sta1', ip="10.0.0.2")
55+
mininet.ns3.setMobilityModel(sta1, None)
56+
mininet.ns3.setVelocity(sta1, 5, 0, 0)
57+
58+
wifi = WifiSegment(standard=ns.wifi.WIFI_PHY_STANDARD_80211g)
59+
wifi.addAp(ap0, channelNumber=11, ssid="opennet_0")
60+
wifi.addAp(ap1, channelNumber=11, ssid="opennet_1")
4561

46-
sta0 = net.addStation('sta0', wifi, ip="10.0.0.1", channelNumber=11, ssid="opennet_0", velocitys=(0, 5, 0))
47-
sta1 = net.addStation('sta1', wifi, ip="10.0.0.2", channelNumber=11, ssid="opennet_1", velocitys=(5, 0, 0))
62+
wifi.addSta(sta0, channelNumber=11, ssid="opennet_0")
63+
wifi.addSta(sta1, channelNumber=11, ssid="opennet_1")
4864

4965
net.addLink(sw0, ap0)
5066
net.addLink(sw0, ap1)

0 commit comments

Comments
 (0)