def updateRoutes( self, lsAlgorithm, switches, linkWeights ):
		
		display.section("Adding Flow table entries...")
		log.infoln('Switch\t Protocols\t Dst-Address\t Actions')
		log.infoln('-------------------------------------------------------')
		weights = [ ( 's'+str(i[0]), 's'+str(i[1]), i[2] )
			for i in linkWeights ]
		# For each switch
		for sourceSwitch in switches:
			routes = lsAlgorithm( sourceSwitch, weights )
			# Compute the least cost route for each destination
			for route in routes:
				# Least cost paths to destinations
				dstSwitch = last(route)
				dstHost = 'h%s' % dstSwitch[1:]
				dstAddress = self.IP(dstHost)
				## Switches to the connected host flows
				srcHost = 'h%s' % sourceSwitch[1:]
				srcAddress = self.IP(srcHost)
				(iPort, oPort) = self.connectionPorts( srcHost, sourceSwitch )
				log.debugln('Source:', (sourceSwitch, srcHost, srcAddress, oPort))
				log.debugln('Destination', (dstSwitch, dstHost, dstAddress, oPort))
				self.flows.add( sourceSwitch, srcAddress, oPort )
				## Switches to switches flows
				prev = sourceSwitch
				for i in range( 1, len(route) ):
					current = route[i]
					(iPort, oPort) = self.connectionPorts( prev, current )
					self.flows.add( prev, dstAddress, iPort )
					prev = current
예제 #2
0
	def do_ifconfigs( self, _line ):
		display.section("Showing Interface Configuration")
		sh = 'ifconfig -a'
		display.subsection('Hosts')
		for h in self.mn.hosts:
			h.cmdPrint( sh )
		display.subsection('Controller')
		self.doPrint( sh )
예제 #3
0
	def do_netstats( self, _line ):
		display.section("Routing Tables")
		sh = 'netstat -rn'
		display.subsection('Hosts')
		for h in self.mn.hosts:
			h.cmdPrint( sh )
		display.subsection('Controller')
		self.doPrint( sh )
예제 #4
0
 def do_stats(self, _):
     display.section("OpenFlow: Sent/Received Packets")
     display.message(
         'Packets passing through a switch on the way host with IP address = "nw_dst"'
     )
     for s in self.mn.switches:
         display.subsection('%s - Traffic' % s.name)
         self.doPrint(
             'sudo ovs-ofctl dump-flows %s | grep -e "n_packets=[1-9]*.*n_bytes=[1-9]*.*nw_dst=10.10.[1-9].[1-9]" -To'
             % (s.name))
예제 #5
0
	def do_xxx_testFlows1( self, _line ):
		display.section("Adding test flows to Tiny Network")
		self.do( 'sudo ovs-ofctl add-flow s1 ip,ip_dst=10.0.0.2,actions=output:1' )
		self.do( 'sudo ovs-ofctl add-flow s1 ip,ip_dst=10.0.0.1,actions=output:4' )
		self.do( 'sudo ovs-ofctl add-flow s2 ip,ip_dst=10.0.0.1,actions=output:1' )
		self.do( 'sudo ovs-ofctl add-flow s2 ip,ip_dst=10.0.0.2,actions=output:3' )
		
		self.do( 'sudo ovs-ofctl add-flow s1 arp,arp_tpa=10.0.0.2,actions=output:1' )
		self.do( 'sudo ovs-ofctl add-flow s1 arp,arp_tpa=10.0.0.1,actions=output:4' )
		self.do( 'sudo ovs-ofctl add-flow s2 arp,arp_tpa=10.0.0.1,actions=output:1' )
		self.do( 'sudo ovs-ofctl add-flow s2 arp,arp_tpa=10.0.0.2,actions=output:3' )
예제 #6
0
	def do_info( self, line ):
		locals = self.getLocals()
		_nodes = line.split()
		display.section("All functions")
		if not (_nodes):
			_nodes = self.mn.keys()
		for n in _nodes:
			if not (locals.__contains__(n)):
				break
			obj = locals[n]
			display.subsection('%s (%s)' % (n, obj.IP()))
			print(dir(obj))
예제 #7
0
	def do_xxx_sharks( self, line ):
		display.section("Launching Wireshark")
		sh = 'sudo wireshark &'
		
		locals = self.getLocals()
		_nodes = line.split()
		if not (_nodes):
			_nodes = self.mn.keys()
		for n in _nodes:
			if not (locals.__contains__(n)):
				break
			obj = locals[n]
			obj.cmdPrint( sh )
예제 #8
0
	def do_paths( self, line ):
		# Algorithm input
		switches = self.mn.topo.switches()
		weights = [ ( 's'+str(i[0]), 's'+str(i[1]), i[2] )
			for i in self.mn.topo._slinks ]
		# Least cost paths to every node
		display.section("Least-cost paths to other nodes")
		display.message('From -> To\tCost\t\tFull Shortest Path')
		for start in switches:
			display.subsection('%s' % start)
			for end in switches:
				if (start == end):
					continue
				route = get_routing_decision( start, weights, end )
				cost = get_route_cost( [route] )
				display.message('%s   -> %s\t%s\t\t%s' % (start, end, cost, route))
예제 #9
0
	def do_ips( self, _ ):
		display.section("IP Addresses")
		locals = self.getLocals()
		def showIP( *keys ):
			for key in keys:
				display.message('%s\t%s' % ( key.name, key.IP() ))
		def showAll( *keys ):
			for key in keys:
				display.message('%s\t%s\t%s' % ( key.name, key.IP(), key.MAC() ))
		# For each node
		display.subsection('Controllers')
		for c in self.mn.controllers:
			showIP( locals[c.name] )
		display.subsection('Switches')
		for s in self.mn.switches:
			showIP( locals[s.name] )
		display.subsection('Hosts')
		for h in self.mn.hosts:
			showAll( locals[h.name] )
예제 #10
0
	def do_routes( self, _ ):
		# Algorithm input
		switches = self.mn.topo.switches()
		weights = [ ( 's'+str(i[0]), 's'+str(i[1]), i[2] )
			for i in self.mn.topo._slinks ]
		# Print next hop switch
		display.section("First-Hop with lowest cost")
		print('From\\To\t'), ('\t'.join(switches))
		for start in switches:
			print(start + '\t'),
			for end in switches:
				if (start == end):
					print('--\t'),
					continue
				route = get_routing_decision( start, weights, end )
				if ( isDirect(route) ):
					# Print result for directly connected switches
					print( end ),
				else:
					# Print and highlight routes with intermediate switches
					print( brightLabel(route[1]) ),
				print('\t'),
			print('')
예제 #11
0
	def do_costs( self, _ ):
		# Algorithm input
		switches = self.mn.topo.switches()
		weights = [ ( 's'+str(i[0]), 's'+str(i[1]), i[2] )
			for i in self.mn.topo._slinks ]
		# Print cost of reaching 'end' switch from 'start' switch
		display.section("Total path costs")
		print('From\\To'), ('\t'.join(switches))
		for start in switches:
			print(start + '\t'),
			for end in switches:
				if (start == end):
					print('--\t'),
					continue
				route = get_routing_decision( start, weights, end )
				cost = get_route_cost( [route] )
				if ( isDirect(route) ):
					# Print result for directly connected switches
					print( cost ),
				else:
					# Print and highlight routes with intermediate switches
					print( brightLabel(cost) ),
				print('\t'),
			print('')
예제 #12
0
	def do_arps( self, _line ):
		display.section("ARP caches of all hosts")
		sh = 'arp -a'
		for h in self.mn.hosts:
			h.cmdPrint( sh )
예제 #13
0
	def do_deleteFlows( self, _line ):
		display.section("Deleting all flows of all OVSSwitches")
		for s in self.mn.switches:
			self.doPrint( 'sudo ovs-ofctl del-flows %s' % s )
예제 #14
0
	def do_flows( self, _line ):
		display.section("Showing all flows of all OVSSwitches")
		for s in self.mn.switches:
			self.doPrint( 'sudo ovs-ofctl dump-flows %s' % s )
예제 #15
0
	def do_weights( self, _ ):
		display.section("Weights")
		log.infoln('Link\t\tWeight')
		log.infoln('--------------------')
		for (i, j, w) in self.mn.topo._slinks:
			log.infoln('{s%s, s%s}\t%s' % (i, j, w))