faucetsdn / ryu

Ryu component-based software defined networking framework
https://ryu-sdn.org
Apache License 2.0
1.51k stars 1.16k forks source link

why datapath id is registered with integer type in ryu/app/simple_switch_rest_13.py ? #171

Open AlfredChaos opened 2 years ago

AlfredChaos commented 2 years ago

When I learned Ryu Rest, I found that the datapath ID is set to int at registration time

@set_ev_cls(ofp_event.EventOFPSwitchFeatures, CONFIG_DISPATCHER)
def switch_features_handler(self, ev):
    super(SimpleSwitchRest13, self).switch_features_handler(ev)
    datapath = ev.msg.datapath
    self.switches[datapath.id] = datapath
    self.mac_to_port.setdefault(datapath.id, {})

so mac_to_port = {1: {}} however, when updating mac_to_port with api, i got dpid is a string, and decorator validates string the dpid.

@route('simpleswitch', url, methods=['PUT'],
     requirements={'dpid': dpid_lib.DPID_PATTERN})

then, string dpid "0000000000000001" not in mac_to_port, return 404.

if dpid not in simple_switch.mac_to_port:
    return Response(status=404)

if i reset bridge datapath-id with command ovs-vsctl set bridge br0 other-config:datapath-id=<random string>, then got random number from event message.