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.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') }
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
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
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
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
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)) ])
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
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
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
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
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))])
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
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)
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)
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')}
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)
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
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