On 05/09/2015 03:59 AM, david jhon wrote:
Hi, I am sorry for sending in five attachments, I cloned the code from here
<https://bitbucket.org/msharif/hedera/src>: Let me explain it here:
Please don't top-post. Your earlier problem description, which I could
make no sense of, is now located after your later "clarification".
Thanks for eliminating the attachments. Many cannot see them. And for
extracting only part of the code into the message. It's still too much
for me, but others may manage it okay. To me, it seems likely that most
of that code will not have any part in the problem you're describing.
And in some places you have code that's missing its context.
Now, eliminate the pieces of code that are irrelevant to your question,
and state the problem in terms that make sense. Somebody is
instantiating an object. Exactly which class is being used for that?
Somebody else is calling a particular method (be specific, rather than
just saying "some method"), and it's giving the wrong results. And
apparently, those wrong results depend on which source file something
happens in.
Routing Base class defined in DCRouting.py:
import logging
from copy import copy
class Routing(object):
'''Base class for data center network routing.
Routing engines must implement the get_route() method.
'''
def __init__(self, topo):
'''Create Routing object.
@param topo Topo object from Net parent
'''
self.topo = topo
def get_route(self, src, dst, hash_):
'''Return flow path.
@param src source host
@param dst destination host
@param hash_ hash value
@return flow_path list of DPIDs to traverse (including hosts)
'''
raise NotImplementedError
def routes(self, src, dst):
''' Return list of paths
Only works for Fat-Tree topology
@ param src source host
@ param dst destination host
@ return list of DPIDs (including inputs)
'''
complete_paths = [] # List of complete dpid routes
src_paths = { src : [[src]] }
dst_paths = { dst : [[dst]] }
dst_layer = self.topo.layer(dst)
src_layer = self.topo.layer(src)
lower_layer = src_layer
if dst_layer > src_layer:
lower_layer = dst_layer
for front_layer in range(lower_layer-1, -1, -1):
if src_layer > front_layer:
# expand src frontier
new_src_paths = {}
for node in sorted(src_paths):
path_list = src_paths[node]
for path in path_list:
last_node = path[-1]
for frontier_node in
self.topo.upper_nodes(last_node):
new_src_paths[frontier_node] = [path +
[frontier_node]]
if frontier_node in dst_paths:
dst_path_list = dst_paths[frontier_node]
for dst_path in dst_path_list:
dst_path_copy = copy ( dst_path )
dst_path_copy.reverse()
complete_paths.append( path +
dst_path_copy)
src_paths = new_src_paths
if dst_layer > front_layer:
# expand dst frontier
new_dst_paths = {}
for node in sorted(dst_paths):
path_list = dst_paths[node]
for path in path_list:
last_node = path[-1]
for frontier_node in
self.topo.upper_nodes(last_node):
new_dst_paths[frontier_node] = [ path +
[frontier_node]]
if frontier_node in src_paths:
src_path_list = src_paths[frontier_node]
dst_path_copy = copy( path )
dst_path_copy.reverse()
for src_path in src_path_list:
complete_paths.append( src_path +
dst_path_copy)
dst_paths = new_dst_paths
if complete_paths:
return complete_paths
class HashedRouting(Routing):
''' Hashed routing '''
def __init__(self, topo):
self.topo = topo
def get_route(self, src, dst, hash_):
''' Return flow path. '''
if src == dst:
return [src]
paths = self.routes(src,dst)
if paths:
#print 'hash_:', hash_
choice = hash_ % len(paths)
#print 'choice:', choice
path = sorted(paths)[choice]
#print 'path:', path
return path
============>
Instantiated in util.py:
from DCTopo import FatTreeTopo
from mininet.util import makeNumeric
from DCRouting import HashedRouting, Routing
TOPOS = {'ft': FatTreeTopo}
ROUTING = {'ECMP' : HashedRouting}
def buildTopo(topo):
topo_name, topo_param = topo.split( ',' )
return TOPOS[topo_name](makeNumeric(topo_param))
def getRouting(routing, topo):
return ROUTING[routing](topo)
A comment on that last line that says it instantiates the child class
would have been very helpful.
But even though I can now search for calls to that function, I still
cannot make sense out of that context, either.
============================> utilized in HController. py:
A Piece of code which works with self.r.routes() method:
Following list of methods are defined in HController.py
def _ecmp_hash(self, packet):
''' Return an ECMP-style 5-tuple hash for TCP/IP packets, otherwise
0.
RFC2992 '''
hash_input = [0] * 5
if isinstance(packet.next, ipv4):
ip = packet.next
hash_input[0] = ip.srcip.toUnsigned()
hash_input[1] = ip.dstip.toUnsigned()
hash_input[2] = ip.protocol
if isinstance(ip.next, tcp) or isinstance(ip.next, udp):
l4 = ip.next
hash_input[3] = l4.srcport
hash_input[4] = l4.dstport
return crc32(pack('LLHHH', *hash_input))
return 0
def _install_reactive_path(self, event, out_dpid, final_out_port,
packet):
''' Install entries on route between two switches. '''
in_name = self.t.node_gen(dpid = event.dpid).name_str()
out_name = self.t.node_gen(dpid = out_dpid).name_str()
hash_ = self._ecmp_hash(packet)
paths = self.r.routes(src_name, dst_name)
if paths == None:
print "PATH is None :("
return
route = self.r.get_route(in_name, out_name, hash_)
print "Route:",route
print '-'*80
if route == None:
print None, "route between", in_name, "and", out_name
return
match = of.ofp_match.from_packet(packet)
for i, node in enumerate(route):
node_dpid = self.t.node_gen(name = node).dpid
if i < len(route) - 1:
next_node = route[i + 1]
out_port, next_in_port = self.t.port(node, next_node)
else:
out_port = final_out_port
self.switches[node_dpid].install(out_port, match, idle_timeout
= 10)
if isinstance(packet.next, of.ipv4) and
isinstance(packet.next.next, of.tcp):
self.matchDict[(packet.next.srcip, packet.next.dstip,
packet.next.next.srcport, packet.next.next.dstport)] = (route, match)
def _handle_PacketIn(self, event):
if not self.all_switches_up:
#log.info("Saw PacketIn before all switches were up -
ignoring." )
return
packet = event.parsed
dpid = event.dpid
in_port = event.port
# Learn MAC address of the sender on every packet-in.
self.macTable[packet.src] = (dpid, in_port)
sw_name = self.t.node_gen(dpid = dpid).name_str()
#print "Sw:", sw_name, packet.src, packet.dst,"port", in_port,
packet.dst.isMulticast(),"macTable", packet.dst in self.macTable
#print '-'*80
# Insert flow, deliver packet directly to destination.
if packet.dst in self.macTable:
out_dpid, out_port = self.macTable[packet.dst]
self._install_reactive_path(event, out_dpid, out_port, packet)
self.switches[out_dpid].send_packet_data(out_port, event.data)
else:
self._flood(event)
===================> code snippet which returns 'None' number of paths.
def _GlobalFirstFit(self,flow):
'''do the Hedera global first fit here'''
src_name = self.t.node_gen(dpid = flow['src']).name_str()
dst_name = self.t.node_gen(dpid = flow['dst']).name_str()
print 'Global Fisrt Fit for the elephant flow from ',src_name,'to',
dst_name
paths = self.r.routes(src_name,dst_name)
print 'all routes found for the big flow:\n',paths
GFF_route = None
if paths == None:
return
else:
for path in paths:
fitCheck = True
for i in range(1,len(path)):
fitCheck = False
if self.bwReservation.has_key(path[i-1]) and
self.bwReservation[path[i-1]].has_key(path[i]):
if
self.bwReservation[path[i-1]][path[i]]['reserveDemand'] + flow['demand'] >
1 :
break
else:
#self.bwReservation[path[i-1]][path[i]]['reserveDemand'] += flow['demand']
fitCheck = True
else:
self.bwReservation[path[i-1]]={}
self.bwReservation[path[i-1]][path[i]]={'reserveDemand':0}
fitCheck = True
if fitCheck == True:
for i in range(1,len(path)):
self.bwReservation[path[i-1]][path[i]]['reserveDemand']
+= flow['demand']
GFF_route = path
print "GFF route found:", path
break
if GFF_route != None:
"""install new GFF_path between source and destintaion"""
self. _install_GFF_path(GFF_route,flow['match'])
def launch(topo = None, routing = None, bw = None ):
#print topo
if not topo:
raise Exception ("Please specify the topology")
else:
t = buildTopo(topo)
r = getRouting(routing, t)
if bw == None:
bw = 10.0 #Mb/s
bw = float(bw/1000) #Gb/s
else:
bw = float(bw)/1000
core.registerNew(HController, t, r, bw)
log.info("** HController is running
I am really sorry for any inconvenience caused. I, ve tried to make it a
bit clear here. I am not even able to debug the code by setting a python
debugging point pdb. I need help from you guys. Thanks a lot again for your
time and help.
Best Regards,
David
On Sat, May 9, 2015 at 12:07 PM, Mark Lawrence <breamore...@yahoo.co.uk>
wrote:
On 09/05/2015 07:41, david jhon wrote:
Hello everyone,
I am new to python and trying to run an example code from mininet tests.
Basically, I am trying to call a method in Hcontroller.py from base class
Routing defined in DCRouting.py which runs and fetches all the required
results in install_reactive_path() method, but it returns None when it is
called from _GlobalFirstFit. I hope someone here could help me fix this
bug..
I am attaching all the three files(DCRouting.py, HController.py, util.py)
to have a look into. Thanks in advance for your time, help or suggestion.
Thanks a lot!
kind regards,
David
I'm sorry but I'm not wading through nearly 30kb of code in five
attachments. Please see http://sscce.org/ for how to put your question
so you're more likely to get answers.
--
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.
Mark Lawrence
--
https://mail.python.org/mailman/listinfo/python-list
--
DaveA
--
https://mail.python.org/mailman/listinfo/python-list