Example #1
0
 def to_dict(self):
     return {
         "dpid": dpid_to_str(self.dpid),
         "port_no": port_no_to_str(self.port_no),
         "hw_addr": self.hw_addr,
         "name": self.name.rstrip("\0"),
     }
Example #2
0
 def to_dict(self):
     return {
         'dpid': dpid_to_str(self.dpid),
         'port_no': port_no_to_str(self.port_no),
         'hw_addr': self.hw_addr,
         'name': self.name.rstrip('\0')
     }
 def to_dict(self):
     return {
         'dpid': dpid_to_str(self.dpid),
         'port_no': port_no_to_str(self.port_no),
         'hw_addr': self.hw_addr,
         'name': self.name.decode('utf-8')
     }
Example #4
0
 def to_dict(self):
     d = {
         "mac": self.mac,
         "ip": self.ip,
         "dpid": dpid_to_str(self.dpid),
         "port_no": port_no_to_str(self.port_no)
     }
     return d
Example #5
0
    def to_dict(self):
        d = {'port_no': port_no_to_str(self.port_no),
             'hw_addr': str(self.hw_addr),
             'name': self.name.rstrip('\0')}

        if self.gateway:
            d['gateway'] = self.gateway.to_dict()
        else:
            d['gateway'] = {}

        if self.neighbor_switch_dpid:
            d['neighbor_switch_dpid'] = dpid_to_str(self.neighbor_switch_dpid)
            d['neighbor_port_no'] = port_no_to_str(self.neighbor_port_no)
        else:
            d['neighbor_switch_dpid'] = ''
            d['neighbor_port_no'] = ''

        return d
Example #6
0
    def to_dict(self):
        r = {}
        if self.receive_port.port_no:
            r['out_port'] = port_no_to_str(self.receive_port.port_no)
        if self.metric != 0:
            r['next_hop'] = dpid_to_str(self.neighbor_port.dpid)
        r['metric'] = self.metric
        r['source'] = self.source
        r['last_update'] = datetime.datetime.fromtimestamp(self.last_update).strftime('%Y-%m-%d %H:%M:%S')

        return r
Example #7
0
    def to_dict(self):
        r = {}
        if self.receive_port.port_no:
            r["out_port"] = port_no_to_str(self.receive_port.port_no)
        if self.metric != 0:
            r["next_hop"] = dpid_to_str(self.neighbor_port.dpid)
        r["metric"] = self.metric
        r["source"] = self.source
        r["last_update"] = datetime.datetime.fromtimestamp(self.last_update).strftime("%Y-%m-%d %H:%M:%S")

        return r
Example #8
0
def add_addresses(addresses, controller_ip):
    for address in addresses:
        ip = address[0]
        router = address[1]
        port = address[2]
        subprocess.call([
            'curl', '-X', 'POST', '-d',
            '{"address": "%s"}' % ip,
            'http://%s:8080/router/%s/%s/address' %
            (controller_ip, dpid_to_str(router), port_no_to_str(port))
        ])
Example #9
0
    def to_dict(self):
        d = {
            'port_no': port_no_to_str(self.port_no),
            'hw_addr': str(self.hw_addr),
            'name': self.name.rstrip('\0')
        }

        if self.gateway:
            d['gateway'] = self.gateway.to_dict()
        else:
            d['gateway'] = {}

        if self.neighbor_switch_dpid:
            d['neighbor_switch_dpid'] = dpid_to_str(self.neighbor_switch_dpid)
            d['neighbor_port_no'] = port_no_to_str(self.neighbor_port_no)
        else:
            d['neighbor_switch_dpid'] = ''
            d['neighbor_port_no'] = ''

        return d
Example #10
0
    def to_dict(self):
        r = {}
        if self.receive_port.port_no:
            r['out_port'] = port_no_to_str(self.receive_port.port_no)
        if self.metric != 0:
            r['next_hop'] = dpid_to_str(self.neighbor_port.dpid)
        r['metric'] = self.metric
        r['last_update'] = datetime.datetime.fromtimestamp(self.last_update).strftime('%Y-%m-%d %H:%M:%S')
        r['flow_entry'] = self.flow_entry

        return r
Example #11
0
 def port_delete_handler(self, event):
     """
         event handler triggered when port deleted.
         get Switch instance and delete specific Port object.
     """
     port = Port(event.port)
     logger.info('port deleted, port_no=%s (dpid=%s)', portno_lib.port_no_to_str(port.port_no), dpid_lib.dpid_to_str(port.dpid))
     try:
         switch = self.switches[port.dpid]
         del switch.ports[port.port_no]
     except KeyError:
         pass
Example #12
0
 def port_add_handler(self, event):
     """
         event handler triggered when port added.
         get Swtich instance and creat a Port object.
     """
     port = Port(event.port)
     try:
         switch = self.switches[port.dpid]
         switch.ports[port.port_no] = port
         logger.info('port added, port_no=%s (dpid=%s)', portno_lib.port_no_to_str(port.port_no), dpid_lib.dpid_to_str(port.dpid))
     except:
         pass
Example #13
0
def add_addresses(addresses, controller_ip):
    for address in addresses:
        ip = address[0]
        router = address[1]
        port = address[2]
        subprocess.call(['curl',
                         '-X',
                         'POST',
                         '-d',
                         '{"address": "%s"}' % ip,
                         'http://%s:8080/router/%s/%s/address' % (
                             controller_ip, dpid_to_str(router),
                             port_no_to_str(port))])
Example #14
0
 def port_add_handler(self, event):
     """
         event handler triggered when port added.
         get Swtich instance and creat a Port object.
     """
     port = Port(event.port)
     try:
         switch = self.switches[port.dpid]
         switch.ports[port.port_no] = port
         logger.info('port added, port_no=%s (dpid=%s)',
                     portno_lib.port_no_to_str(port.port_no),
                     dpid_lib.dpid_to_str(port.dpid))
     except:
         pass
Example #15
0
 def port_delete_handler(self, event):
     """
         event handler triggered when port deleted.
         get Switch instance and delete specific Port object.
     """
     port = Port(event.port)
     logger.info('port deleted, port_no=%s (dpid=%s)',
                 portno_lib.port_no_to_str(port.port_no),
                 dpid_lib.dpid_to_str(port.dpid))
     try:
         switch = self.switches[port.dpid]
         del switch.ports[port.port_no]
     except KeyError:
         pass
Example #16
0
 def port_add_handler(self, event):
     """
        event handler triggered when port added.
        get Switch instance and create a Port object.
     """
     print "######################## port status ###########################"
     print vars(event)
     msg = event.msg
     dpid =msg.datapath.id
     try: 
        self.routers[dpid].add_port(event.port.port_no,netaddr.EUI(event.port.hw_addr),event.port.name)
        logger.info('port %s added ',event.port.name)
        logger.info('port added, port_no=%s (dpid=%s)', portno_lib.port_no_to_str(port.port_no), dpid_lib.dpid_to_str(port.dpid))
     except:
           pass
Example #17
0
 def _port_stats_reply_handler(self, ev):
     # print '*'*100
     body = ev.msg.body
     dpid_str = dpid_to_str(ev.msg.datapath.id)
     for stat in sorted(body, key=attrgetter('port_no')):
         port_data = {}  #save th port data   {'rx-pkts':  ,'tx-pkts':  }
         port_no = stat.port_no
         # if (hex(port_no) != '0xfffffffe'):         # except for the port to controller
         # calculate Remain BandWidth
         new_tbytes = stat.tx_bytes
         port_no_str = port_no_to_str(port_no)
         if (Port_stats[dpid_str].has_key(port_no_str) == True):
             old_tbytes = Port_stats[dpid_str][port_no_str]['tx_bytes']
             remainBandWidth = self.calRBW(new_tbytes, old_tbytes)
         else:
             # print '******the case of first statics******'
             remainBandWidth = self.calRBW(
                 new_tbytes=new_tbytes)  # the case of first statics
         port_data['rx-pkts'] = stat.rx_packets
         port_data['tx-pkts'] = stat.tx_packets
         port_data['rx-bytes'] = stat.rx_bytes
         port_data['tx_bytes'] = stat.tx_bytes
         port_data['rx-errors'] = stat.rx_errors
         port_data['tx-errors'] = stat.tx_errors
         port_data['rx_dropped'] = stat.rx_dropped
         port_data['tx_dropped'] = stat.tx_dropped
         port_data['remainBandWidth-Mbps'] = remainBandWidth
         Port_stats[dpid_str][port_no_str] = port_data
     # pprint.pprint(Port_stats)
     Port_stats_json = json.dumps(Port_stats, indent=4)
     # print Port_stats_json
     f = open('./Info/Dynamic/Port_stats.json', 'w+')
     # time = time.strftime('%Y-%m-%d %H:%M:%S')
     # f.write(time+'\n')
     f.write(Port_stats_json)
     f.close()
     self.logger.info(
         "******_port_stats_reply_handler, gets Port_stats of %s******",
         dpid_str)
Example #18
0
 def _port_stats_reply_handler(self, ev):
     # print '*'*100
     body = ev.msg.body
     dpid_str = dpid_to_str(ev.msg.datapath.id)
     for stat in sorted(body, key=attrgetter('port_no')):
         port_data = {}          #save th port data   {'rx-pkts':  ,'tx-pkts':  }
         port_no = stat.port_no
         # if (hex(port_no) != '0xfffffffe'):         # except for the port to controller
         # calculate Remain BandWidth 
         new_tbytes = stat.tx_bytes
         port_no_str = port_no_to_str(port_no)
         if(  Port_stats[dpid_str].has_key(port_no_str)==True ):
             old_tbytes = Port_stats[dpid_str][port_no_str]['tx_bytes']
             remainBandWidth = self.calRBW( new_tbytes, old_tbytes )
         else:
             # print '******the case of first statics******'
             remainBandWidth = self.calRBW(new_tbytes=new_tbytes)  # the case of first statics
         port_data['rx-pkts'] = stat.rx_packets
         port_data['tx-pkts'] = stat.tx_packets
         port_data['rx-bytes'] = stat.rx_bytes
         port_data['tx_bytes'] = stat.tx_bytes
         port_data['rx-errors'] = stat.rx_errors
         port_data['tx-errors'] = stat.tx_errors
         port_data['rx_dropped'] = stat.rx_dropped
         port_data['tx_dropped'] = stat.tx_dropped
         port_data['remainBandWidth-Mbps'] = remainBandWidth
         Port_stats[dpid_str][port_no_str]= port_data
     # pprint.pprint(Port_stats)
     Port_stats_json=json.dumps(Port_stats, indent=4)
     # print Port_stats_json
     f = open('./Info/Dynamic/Port_stats.json','w+')
     # time = time.strftime('%Y-%m-%d %H:%M:%S')
     # f.write(time+'\n')
     f.write(Port_stats_json)
     f.close()
     self.logger.info("******_port_stats_reply_handler, gets Port_stats of %s******", dpid_str)
Example #19
0
 def to_dict(self):
     return {'dpid': dpid_to_str(self.dpid),
             'port_no': port_no_to_str(self.port_no),
             'hw_addr': self.hw_addr,
             'name': self.name.decode('utf-8')}
Example #20
0
 def __init__(self, dpid, port_no):
     self.dpid = dpid_lib.dpid_to_str(dpid)
     self.port_no = port_no_lib.port_no_to_str(port_no)
Example #21
0
 def to_dict(self):
     d = super(Port, self).to_dict()
     d['peer_switch_dpid'] = dpid_to_str(self.peer_switch_dpid)
     d['peer_port_no'] = port_no_to_str(self.peer_port_no)
     d['is_border'] = 'True' if self.is_border else 'False'
     return d
Example #22
0
 def to_dict(self):
     return {'dpid': dpid_to_str(self.dpid),
             'port_no': port_no_to_str(self.port_no),
             'hw_addr': self.hw_addr,
             'name': self.name.rstrip('\0')}
 def to_dict(self):
     d = super(Port, self).to_dict()
     d['peer_switch_dpid'] = dpid_to_str(self.peer_switch_dpid)
     d['peer_port_no'] = port_no_to_str(self.peer_port_no)
     d['is_border'] = 'True' if self.isBorder else 'False'
     return d