Guest User

Untitled

a guest
Feb 18th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.68 KB | None | 0 0
  1. diff --git a/P4D2_2018_East/exercises/basic/topology.json b/P4D2_2018_East/exercises/basic/topology.json
  2. index e33477c..f101b9c 100644
  3. --- a/P4D2_2018_East/exercises/basic/topology.json
  4. +++ b/P4D2_2018_East/exercises/basic/topology.json
  5. @@ -1,16 +1,16 @@
  6. {
  7. - "hosts": [
  8. - "h1",
  9. - "h2",
  10. - "h3"
  11. + "stations": [
  12. + "sta1",
  13. + "sta2",
  14. + "sta3"
  15. ],
  16. - "switches": {
  17. - "s1": { "cli_input" : "s1-commands.txt" },
  18. - "s2": { "cli_input" : "s2-commands.txt" },
  19. - "s3": { "cli_input" : "s3-commands.txt" }
  20. + "aps": {
  21. + "ap1": { "cli_input" : "s1-commands.txt" },
  22. + "ap2": { "cli_input" : "s2-commands.txt" },
  23. + "ap3": { "cli_input" : "s3-commands.txt" }
  24. },
  25. "links": [
  26. - ["h1", "s1"], ["s1", "s2"], ["s1", "s3"],
  27. - ["s3", "s2"], ["s2", "h2"], ["s3", "h3"]
  28. + ["sta1", "ap1"], ["ap1", "ap2"], ["ap1", "ap3"],
  29. + ["ap3", "ap2"], ["ap2", "sta2"], ["ap3", "sta3"]
  30. ]
  31. }
  32. diff --git a/P4D2_2018_East/utils/mininet/p4_mininet.py b/P4D2_2018_East/utils/mininet/p4_mininet.py
  33. index 8abe79f..fc68d0a 100644
  34. --- a/P4D2_2018_East/utils/mininet/p4_mininet.py
  35. +++ b/P4D2_2018_East/utils/mininet/p4_mininet.py
  36. @@ -14,7 +14,7 @@
  37. #
  38.  
  39. from mininet.net import Mininet
  40. -from mininet.node import Switch, Host
  41. +from mn_wifi.node import AP, Station
  42. from mininet.log import setLogLevel, info, error, debug
  43. from mininet.moduledeps import pathCheck
  44. from sys import exit
  45. @@ -23,7 +23,7 @@ import os
  46. import tempfile
  47. import socket
  48.  
  49. -class P4Host(Host):
  50. +class P4Host(Station):
  51. def config(self, **params):
  52. r = super(P4Host, self).config(**params)
  53.  
  54. @@ -50,7 +50,7 @@ class P4Host(Host):
  55. print "Default route to switch: %s (%s)" % (sw_addr, sw_mac)
  56. print "**********"
  57.  
  58. -class P4Switch(Switch):
  59. +class P4Switch(AP):
  60. """P4 virtual switch"""
  61. device_id = 0
  62.  
  63. diff --git a/P4D2_2018_East/utils/p4_mininet.py b/P4D2_2018_East/utils/p4_mininet.py
  64. index b7fbbcd..fdabd6c 100644
  65. --- a/P4D2_2018_East/utils/p4_mininet.py
  66. +++ b/P4D2_2018_East/utils/p4_mininet.py
  67. @@ -13,8 +13,8 @@
  68. # limitations under the License.
  69. #
  70.  
  71. -from mininet.net import Mininet
  72. -from mininet.node import Switch, Host
  73. +from mn_wifi.net import Mininet_wifi
  74. +from mn_wifi.node import AP, Station
  75. from mininet.log import setLogLevel, info, error, debug
  76. from mininet.moduledeps import pathCheck
  77. from sys import exit
  78. @@ -27,9 +27,9 @@ from netstat import check_listening_on_port
  79.  
  80. SWITCH_START_TIMEOUT = 10 # seconds
  81.  
  82. -class P4Host(Host):
  83. +class P4Host(Station):
  84. def config(self, **params):
  85. - r = super(Host, self).config(**params)
  86. + r = super(Station, self).config(**params)
  87.  
  88. self.defaultIntf().rename("eth0")
  89.  
  90. @@ -54,7 +54,7 @@ class P4Host(Host):
  91. )
  92. print "**********"
  93.  
  94. -class P4Switch(Switch):
  95. +class P4Switch(AP):
  96. """P4 virtual switch"""
  97. device_id = 0
  98.  
  99. @@ -66,7 +66,7 @@ class P4Switch(Switch):
  100. device_id = None,
  101. enable_debugger = False,
  102. **kwargs):
  103. - Switch.__init__(self, name, **kwargs)
  104. + AP.__init__(self, name, **kwargs)
  105. assert(sw_path)
  106. assert(json_path)
  107. # make sure that the provided sw_path is valid
  108. diff --git a/P4D2_2018_East/utils/run_exercise.py b/P4D2_2018_East/utils/run_exercise.py
  109. index 84997d7..5542924 100755
  110. --- a/P4D2_2018_East/utils/run_exercise.py
  111. +++ b/P4D2_2018_East/utils/run_exercise.py
  112. @@ -24,10 +24,13 @@ from time import sleep
  113.  
  114. from p4_mininet import P4Switch, P4Host
  115.  
  116. -from mininet.net import Mininet
  117. -from mininet.topo import Topo
  118. +from mn_wifi.net import Mininet_wifi
  119. +from mn_wifi.topo import Topo_WiFi
  120. from mininet.link import TCLink
  121. -from mininet.cli import CLI
  122. +from mn_wifi.cli import CLI_wifi
  123. +
  124. +from mn_wifi.link import wmediumd
  125. +from mn_wifi.wmediumdConnector import interference
  126.  
  127. from p4runtime_switch import P4RuntimeSwitch
  128.  
  129. @@ -60,22 +63,29 @@ def configureP4Switch(**switch_args):
  130. def describe(self):
  131. print "%s -> Thrift port: %d" % (self.name, self.thrift_port)
  132.  
  133. + #@classmethod
  134. + def renameIface(self, intf, newname):
  135. + "Rename interface"
  136. + self.pexec('ip link set %s down' % intf)
  137. + self.pexec('ip link set %s name %s' % (intf, newname))
  138. + self.pexec('ip link set %s up' % newname)
  139. +
  140. return ConfiguredP4Switch
  141.  
  142.  
  143. -class ExerciseTopo(Topo):
  144. +class ExerciseTopo(Topo_WiFi):
  145. """ The mininet topology class for the P4 tutorial exercises.
  146. A custom class is used because the exercises make a few topology
  147. assumptions, mostly about the IP and MAC addresses.
  148. """
  149. - def __init__(self, hosts, switches, links, log_dir, **opts):
  150. - Topo.__init__(self, **opts)
  151. + def __init__(self, stations, aps, links, log_dir, **opts):
  152. + Topo_WiFi.__init__(self, **opts)
  153. host_links = []
  154. switch_links = []
  155. self.sw_port_mapping = {}
  156.  
  157. for link in links:
  158. - if link['node1'][0] == 'h':
  159. + if link['node2'][0] == 's':
  160. host_links.append(link)
  161. else:
  162. switch_links.append(link)
  163. @@ -85,22 +95,25 @@ class ExerciseTopo(Topo):
  164. host_links.sort(key=link_sort_key)
  165. switch_links.sort(key=link_sort_key)
  166.  
  167. - for sw in switches:
  168. - self.addSwitch(sw, log_file="%s/%s.log" %(log_dir, sw))
  169. + aps = sorted(aps)
  170. + aps.sort(key=len, reverse=False)
  171. + for sw in aps:
  172. + sw_num = aps.index(sw) * 50 + 50
  173. + self.addAccessPoint(sw, log_file="%s/%s.log" %(log_dir, sw), position='%s,100,0' % sw_num)
  174.  
  175. for link in host_links:
  176. - host_name = link['node1']
  177. - host_sw = link['node2']
  178. - host_num = int(host_name[1:])
  179. - sw_num = int(host_sw[1:])
  180. + host_name = link['node2']
  181. + host_sw = link['node1']
  182. + host_num = int(host_name[3:])
  183. + sw_num = int(host_sw[2:])
  184. host_ip = "10.0.%d.%d" % (sw_num, host_num)
  185. host_mac = '00:00:00:00:%02x:%02x' % (sw_num, host_num)
  186. # Each host IP should be /24, so all exercise traffic will use the
  187. # default gateway (the switch) without sending ARP requests.
  188. - self.addHost(host_name, ip=host_ip+'/24', mac=host_mac)
  189. + self.addStation(host_name, ip=host_ip+'/24', mac=host_mac, position='%s,50,0' % (host_num*50))
  190. self.addLink(host_name, host_sw,
  191. - delay=link['latency'], bw=link['bandwidth'],
  192. - addr1=host_mac, addr2=host_mac)
  193. + delay=link['latency'], bw=link['bandwidth']) #,
  194. + #addr1=host_mac, addr2=host_mac)
  195. self.addSwitchPort(host_sw, host_name)
  196.  
  197. for link in switch_links:
  198. @@ -175,8 +188,9 @@ class ExerciseRunner:
  199. self.logger('Reading topology file.')
  200. with open(topo_file, 'r') as f:
  201. topo = json.load(f)
  202. - self.hosts = topo['hosts']
  203. - self.switches = topo['switches']
  204. +
  205. + self.stations = topo['stations']
  206. + self.aps = topo['aps']
  207. self.links = self.parse_links(topo['links'])
  208.  
  209. # Ensure all the needed directories exist and are directories
  210. @@ -235,8 +249,8 @@ class ExerciseRunner:
  211. if len(link) > 3:
  212. link_dict['bandwidth'] = link[3]
  213.  
  214. - if link_dict['node1'][0] == 'h':
  215. - assert link_dict['node2'][0] == 's', 'Hosts should be connected to switches, not ' + str(link_dict['node2'])
  216. + if link_dict['node1'][0] == 's':
  217. + assert link_dict['node2'][0] == 'a', 'Hosts should be connected to switches, not ' + str(link_dict['node2'])
  218. links.append(link_dict)
  219. return links
  220.  
  221. @@ -250,7 +264,7 @@ class ExerciseRunner:
  222. """
  223. self.logger("Building mininet topology.")
  224.  
  225. - self.topo = ExerciseTopo(self.hosts, self.switches.keys(), self.links, self.log_dir)
  226. + self.topo = ExerciseTopo(self.stations, self.aps.keys(), self.links, self.log_dir)
  227.  
  228. switchClass = configureP4Switch(
  229. sw_path=self.bmv2_exe,
  230. @@ -258,12 +272,15 @@ class ExerciseRunner:
  231. log_console=True,
  232. pcap_dump=self.pcap_dir)
  233.  
  234. - self.net = Mininet(topo = self.topo,
  235. - link = TCLink,
  236. - host = P4Host,
  237. - switch = switchClass,
  238. - controller = None)
  239. + self.net = Mininet_wifi(topo = self.topo,
  240. + station = P4Host,
  241. + accessPoint = switchClass,
  242. + controller = None,
  243. + link=wmediumd,
  244. + wmediumd_mode=interference,
  245. + plot=True)
  246.  
  247. + self.net.plotGraph(max_x=300, max_y=300)
  248.  
  249. def program_switches(self):
  250. """ If any command files were provided for the switches,
  251. @@ -275,7 +292,7 @@ class ExerciseRunner:
  252. been called.
  253. """
  254. cli = 'simple_switch_CLI'
  255. - for sw_name, sw_dict in self.switches.iteritems():
  256. + for sw_name, sw_dict in self.aps.iteritems():
  257. if 'cli_input' not in sw_dict: continue
  258. # get the port for this particular switch's thrift server
  259. sw_obj = self.net.get(sw_name)
  260. @@ -296,21 +313,21 @@ class ExerciseRunner:
  261. - A mininet instance is stored as self.net and self.net.start() has
  262. been called.
  263. """
  264. - for host_name in self.topo.hosts():
  265. + for host_name in self.topo.stations():
  266. h = self.net.get(host_name)
  267. h_iface = h.intfs.values()[0]
  268. link = h_iface.link
  269.  
  270. sw_iface = link.intf1 if link.intf1 != h_iface else link.intf2
  271. # phony IP to lie to the host about
  272. - host_id = int(host_name[1:])
  273. + host_id = int(host_name[3:])
  274. sw_ip = '10.0.%d.254' % host_id
  275.  
  276. # Ensure each host's interface name is unique, or else
  277. # mininet cannot shutdown gracefully
  278. - h.defaultIntf().rename('%s-eth0' % host_name)
  279. + h.defaultIntf().rename('%s-wlan0' % host_name)
  280. # static arp entries and default routes
  281. - h.cmd('arp -i %s -s %s %s' % (h_iface.name, sw_ip, sw_iface.mac))
  282. + #h.cmd('arp -i %s -s %s %s' % (h_iface.name, sw_ip, sw_iface.mac))
  283. h.cmd('ethtool --offload %s rx off tx off' % h_iface.name)
  284. h.cmd('ip route add %s dev %s' % (sw_ip, h_iface.name))
  285. h.setDefaultRoute("via %s" % sw_ip)
  286. @@ -323,9 +340,9 @@ class ExerciseRunner:
  287. - A mininet instance is stored as self.net and self.net.start() has
  288. been called.
  289. """
  290. - for s in self.net.switches:
  291. + for s in self.net.aps:
  292. s.describe()
  293. - for h in self.net.hosts:
  294. + for h in self.net.stations:
  295. h.describe()
  296. self.logger("Starting mininet CLI")
  297. # Generate a message that will be printed by the Mininet CLI to make
  298. @@ -347,10 +364,10 @@ class ExerciseRunner:
  299. print(' tail -f %s/<switchname>.log' % self.log_dir)
  300. print('')
  301. print('To view the switch output pcap, check the pcap files in %s:' % self.pcap_dir)
  302. - print(' for example run: sudo tcpdump -xxx -r s1-eth1.pcap')
  303. + print(' for example run: sudo tcpdump -xxx -r ap1-eth1.pcap')
  304. print('')
  305.  
  306. - CLI(self.net)
  307. + CLI_wifi(self.net)
  308.  
  309.  
  310. def get_args():
  311. @@ -371,8 +388,8 @@ def get_args():
  312.  
  313.  
  314. if __name__ == '__main__':
  315. - # from mininet.log import setLogLevel
  316. - # setLogLevel("info")
  317. + #from mininet.log import setLogLevel
  318. + #setLogLevel("debug")
  319.  
  320. args = get_args()
  321. exercise = ExerciseRunner(args.topo, args.log_dir, args.pcap_dir,
Add Comment
Please, Sign In to add comment