Earn Up To 100's of $ per Day with Ease!

2007-10-30 Thread jhon
Tired of business opportunities that do not deliver what they promise?

Get Free Advice & a Honest Review on Internet Opportunities that Work!

MOre details http://powerfulmoneymakingideas.blogspot.com/

-- 
http://mail.python.org/mailman/listinfo/python-list


Exception in thread Thread-4:

2015-05-05 Thread david jhon
Hello everyone,

I am initializing lock and threading related variables in __init__() method
of the class as follows:

from threading import Timer, Lock

class miTestClass(EventMixin):
def __init__(self, t, r, bw):
 self.statMonitorLock = Lock() #to lock the multi access threads
 self.statMonitorLock.acquire()
 statMonitorTimer = Timer(10.0, self._collectFlowStats()) #timer to
collect stats
 statMonitorTimer.start()

but I am getting following error:

Exception in thread Thread-4:
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner
self.run()
  File "/usr/lib/python2.7/threading.py", line 1082, in run
self.function(*self.args, **self.kwargs)
TypeError: 'NoneType' object is not callable

I am new to python and after reading various links, I am not able to
resolve this error.
I hope anybody here could help me get it fixed. Many thanks in advance!

Regards,
David
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Exception in thread Thread-4:

2015-05-05 Thread david jhon
Hi Chris,

Thanks a lot for such a comprehensive reply, I got it fixed now. Thanks
again :)

On Tue, May 5, 2015 at 2:52 PM, Chris Angelico  wrote:

> On Tue, May 5, 2015 at 7:23 PM, david jhon  wrote:
> > from threading import Timer, Lock
> >
> > class miTestClass(EventMixin):
> > def __init__(self, t, r, bw):
> >  self.statMonitorLock = Lock() #to lock the multi access threads
> >  self.statMonitorLock.acquire()
> >  statMonitorTimer = Timer(10.0, self._collectFlowStats()) #timer
> to
> > collect stats
> >  statMonitorTimer.start()
> >
> > but I am getting following error:
> >
> > Exception in thread Thread-4:
> > Traceback (most recent call last):
> >   File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner
> > self.run()
> >   File "/usr/lib/python2.7/threading.py", line 1082, in run
> > self.function(*self.args, **self.kwargs)
> > TypeError: 'NoneType' object is not callable
>
> The Timer() class will call a function when it's ready. To use that,
> you want to pass it a function. Try putting these two lines of code
> into your __init__ function:
>
> print(self._collectFlowStats)
> print(self._collectFlowStats())
>
> (Aside: This is something I like to call "IIDPIO debugging": If In
> Doubt, Print It Out. You sometimes have more sophisticated debugging
> techniques available, but you hardly ever are unable to basic 'print',
> in some form or another. It's incredibly useful.)
>
> The first one will print out something like this:
>
>  object at 0x12345678>>
>
> The second will actually call that function (which may or may not do
> anything visible), and then print out:
>
> None
>
> If you change your _collectFlowStats function a bit, you can see even
> more of what's happening. Something like this:
>
> def _collectFlowStats(self):
> print("_collectFlowStats has been called. Returning 42...")
> return 42
>
> Then you'll see that it gets called, and does its print, and then 42
> gets printed out at the end.
>
> In your case, simply removing the parentheses from
> self._collectFlowStats should do what you want - the Timer constructor
> will be passed a function (in this case, a bound method, but same
> same), and that function won't be called until the timer is up.
>
> Hope that helps!
>
> ChrisA
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


calling base class method fetches no results

2015-05-08 Thread david jhon
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
''' Simple hashed-based routing

@author: Milad Sharif ([email protected])
'''

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

#!/usr/bin/python

'''
Fat tree topology for data center networking

@author Milad Sharif ([email protected])

'''

from mininet.topo import Topo


class FatTreeNode(object):

def __init__(self, pod = 0, sw = 0, host = 0, name = None, dpid = None):
''' Create FatTreeNode '''
if dpid:
self.pod = ( dpid & 0xff ) >> 16
self.sw = ( dpid & 0xff00 ) >> 8
self.host = ( dpid & 0xff )
self.dpid = dpid
else:
if name:
pod, sw, host = [int(s) for s in name.split('h')]

self.

Re: calling base class method fetches no results

2015-05-09 Thread david jhon
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(HCo

Re: calling base class method fetches no results

2015-05-09 Thread david jhon
I am really sorry for any inconvenience caused, I was trying to fix this
bug from last 2 days so I had to post it here. It now has been resolved.
Thanks a lot for your time. I'll be careful again. Have a great weekend!

On Sat, May 9, 2015 at 4:36 PM, Dave Angel  wrote:

> 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]
>>