Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #90271

Re: calling base class method fetches no results

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!hq-usenetpeers.eweka.nl!hq-usenetpeers.eweka.nl!border1.nntp.ams1.giganews.com!nntp.giganews.com!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <djhon9813@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'insert': 0.05; 'url:bitbucket': 0.05; 'debug': 0.07; 'debugging': 0.07; 'method.': 0.07; 'none,': 0.07; 'none:': 0.07; 'paths': 0.07; 'tests.': 0.07; 'advance': 0.07; '#print': 0.09; '[0]': 0.09; 'dst': 0.09; 'guys.': 0.09; 'lawrence': 0.09; 'method,': 0.09; 'method:': 0.09; 'snippet': 0.09; 'subject:method': 0.09; 'tcp/ip': 0.09; 'runs': 0.10; 'cc:addr:python-list': 0.11; 'python': 0.11; 'def': 0.12; 'language.': 0.14; '"""install': 0.16; "'''": 0.16; "','": 0.16; '-1):': 0.16; '-1,': 0.16; 'attaching': 0.16; 'caused.': 0.16; 'dst):': 0.16; 'dst,': 0.16; 'dst:': 0.16; 'elephant': 0.16; 'event):': 0.16; 'fetches': 0.16; 'flow,': 0.16; 'hashed': 0.16; 'instantiated': 0.16; 'lot!': 0.16; 'param': 0.16; 'path.': 0.16; 'paths.': 0.16; 'src': 0.16; 'src,': 0.16; 'subject:class': 0.16; 'suggestion.': 0.16; 'switches': 0.16; 'traverse': 0.16; 'true:': 0.16; 'exception': 0.16; 'sat,': 0.16; 'skip:= 10': 0.16; 'language': 0.16; 'fix': 0.17; 'wrote:': 0.18; 'bit': 0.19; 'trying': 0.19; '&lt;': 0.19; 'everyone,': 0.19; 'skip:p 40': 0.19; 'fit': 0.20; 'help.': 0.21; 'example': 0.22; 'import': 0.22; 'cc:addr:python.org': 0.22; 'print': 0.22; 'install': 0.23; 'entries': 0.24; 'specify': 0.24; 'question': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'source': 0.25; '&gt;': 0.26; 'logging': 0.26; 'nearly': 0.26; 'defined': 0.27; 'skip:_ 20': 0.27; 'header:In-Reply-To:1': 0.27; 'tried': 0.27; 'point': 0.28; 'host': 0.29; 'skip:p 30': 0.29; 'raise': 0.29; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'url:mailman': 0.30; 'code': 0.31; "skip:' 10": 0.31; 'node': 0.31; 'object.': 0.31; 'piece': 0.31; 'skip:= 20': 0.31; 'class': 0.32; 'run': 0.32; '(including': 0.33; 'url:python': 0.33; 'running': 0.33; 'mac': 0.33; 'skip:# 10': 0.33; 'skip:& 30': 0.33; 'skip:t 40': 0.33; 'skip:_ 10': 0.34; 'skip:d 20': 0.34; 'could': 0.34; 'skip:s 30': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'really': 0.36; 'event,': 0.36; 'false': 0.36; 'url:listinfo': 0.36; 'method': 0.36; 'thanks': 0.36; 'hi,': 0.36; 'url:org': 0.36; 'two': 0.37; 'list': 0.37; 'clear': 0.37; 'implement': 0.38; 'skip:o 20': 0.38; 'skip:& 10': 0.38; 'skip:[ 10': 0.38; 'pm,': 0.38; 'skip:_ 40': 0.38; 'here:': 0.62; 'complete': 0.62; 'address': 0.63; 'kind': 0.63; 'skip:n 10': 0.64; 'our': 0.64; 'more': 0.64; 'here': 0.66; 'between': 0.67; 'results': 0.69; '8bit%:100': 0.72; 'url:info': 0.73; '2015': 0.84; 'route': 0.84; 'subject:base': 0.84; 'to:addr:yahoo.co.uk': 0.84; 'url:log': 0.84; 'utilized': 0.84; '\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0': 0.84; 'destination': 0.91; 'subject:results': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=6Y7u84yNZv4RPAaLi/BTZQOU8nGgBdpmBEeKBWvB3Us=; b=ApgZaL2CS054wb+t2dkA5JRVaLOvStibRbm8MsnWQDPZUJ1EL+z2uWtX+VaIkLMkbD VUAO5VULSP+CRCnjUf0E6yh9Ldp8dm7br4BShDc2dhk/p60KpYi40drlg1O7mEEusNnN abpQDIBwanvuSpWbk4LxoW6346otRJWlyhy/4UdFTGfUTA/gAmBeCFdy7MNbnqwewbxx 66H1OAwGFjfM/6WF2PPrjF4mh1ahIae+DmK7Y1zJ6TD+hnfPKeow6Lyt0BInaMQv30yb G9FxO7laDlKbd/8CzaF4jHyiXyzHzeonN2braM7gXvaJdXyvidkvrd9Bzqx6v/4CQ11u FBTA==
MIME-Version 1.0
X-Received by 10.42.197.65 with SMTP id ej1mr1871470icb.13.1431158360251; Sat, 09 May 2015 00:59:20 -0700 (PDT)
In-Reply-To <mikbn3$tc3$1@ger.gmane.org>
References <CANPUzQ1QJrg7GKRTpfvKLivG+vbNAY+gYeBSsB_zrJmX=4tRFQ@mail.gmail.com> <mikbn3$tc3$1@ger.gmane.org>
Date Sat, 9 May 2015 12:59:20 +0500
Subject Re: calling base class method fetches no results
From david jhon <djhon9813@gmail.com>
To Mark Lawrence <breamoreboy@yahoo.co.uk>
Cc python-list@python.org
Content-Type multipart/alternative; boundary=20cf303ea680ae24d50515a1850e
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.276.1431158369.12865.python-list@python.org> (permalink)
Lines 612
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1431158369 news.xs4all.nl 2899 [2001:888:2000:d::a6]:59705
X-Complaints-To abuse@xs4all.nl
X-Received-Bytes 37807
X-Received-Body-CRC 4152984005
Xref csiph.com comp.lang.python:90271

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

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:

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)

============================> 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 <breamoreboy@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
>

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: calling base class method fetches no results david jhon <djhon9813@gmail.com> - 2015-05-09 12:59 +0500

csiph-web