On Nov 19, 2013, at 4:01 AM, Amer <amer7...@hotmail.com> wrote: > Thank you Murphy > > I have another question: > I have got the switch MAC address, i.e., 00-00-00-00-0x, how can I convert it > to dpid. > I am working in l2_multi, while the switches array has something like [1: > 00-00-00-00-01, 2: 00-00-00-00-02 ] > is there a way to get the dpid number from switches array or I must use a > specific command to convert from MAC to dpid.
In general, there's no way to convert a MAC to a DPID. However, everything you see when printing out "switches" is already a DPID. Look at the l2_multi code: 44 # Switches we know of. [dpid] -> Switch 45 switches = {} So we see it's not an array. It's a map from DPID to a Switch object. The keys are DPIDs. The values are Switches. When you print it out, you don't see "<Switch object at 0x12345678>", though. Hmm; why not? Let's take a look... 230 class Switch (EventMixin): ... 238 def __repr__ (self): 239 return dpid_to_str(self.dpid) Ah-ha. So that's not a MAC at all. It's also the DPID, but formatted with dpid_to_str(). POX treats DPIDs as numbers. That's what the keys of the switches dictionary are. For display to humans, POX components usually format them with dpid_to_str(), which (purposely) produces something which often looks a lot like an Ethernet address, and that's what you're seeing as the values of the switches dictionary. One easy way to tell them apart is that Ethernet addresses in POX always have the bytes separated by a colon. DPIDs have bytes separated by dashes. Hope that helps. -- Murphy > Best regards, > Amer > > On ١٩/١١/٢٠١٣, at ٧:٢١ ص, Murphy McCauley <murphy.mccau...@gmail.com> wrote: > >> I think you may have to modify l2_multi a bit to get this to work with it -- >> it was designed with the assumption that it's in control of all the >> switches, and I think that will cause problems. >> >> l2_learning, on the other hand, should be easy to run on individual >> switches. And l2_pairs should be pretty easy too. >> >> I'd suggest not doing it by writing your own PacketIn handler and >> demultiplexing it yourself. Instead, just have your L2 stuff listen to >> PacketIns from some switches, and your L3 stuff listen to PacketIns from the >> others. That is, you should make this decision in response to a >> ConnectionUp event instead of each PacketIn. Something like... >> >> from pox.forwarding.l2_learning import LearningSwitch >> >> def _handle_ConnectionUp (event): >> if event.dpid == 1: >> LearningSwitch(event.connection, False) >> else: >> # initialize your L3 thing, binding its events to this connection >> >> >> Hope that helps. >> >> -- Murphy >> >> On Nov 15, 2013, at 10:17 AM, Amer <amer7...@hotmail.com> wrote: >> >>> Hello, >>> >>> >>> I want to create a handle packetin method, if the incoming packet is from >>> specific switch run l2 if it from another run l3 >>> What I did >>> >>> from pox.forearding.l2_multi import * >>> >>> def H_P (event): >>> p = event.parsed >>> If (p.dpid == "1"): >>> sw= Switch() >>> sw._handle_PacketIn(event) >>> Else: >>> #. L3.learning >>> >>> I have received this error: >>> NoneType object has no Len() >>> >>> Pox.py l2l3 openflow.discovery >>> >>> Any help is appreciated >>> >>> Best regards, >>> Amer >> >>