[pox-dev] implementing vlans
durga
c.vijaya.durga at gmail.com
Mon Nov 4 21:32:54 PST 2013
Hello All,
I tried to replicate vlan behaviour and succeeded to some extent(excl.
Broadcasts). The procedure I followed is to maintain another vlanport table
within the controller and map for vlanID to port ID based on simple
calculation of even and odd ports. if both src and dest port are in same
vlan , then controller inserts a flowtable entry , else drop the packet. I
am yet to implement a Broadcast scenario within a single vlan.
Now,
1.is there already a built in feature for implementing vlans? I understand,
there is an action type vlan_vid to set the vlanID in flow tables, so does
it mean that if a match exists in the Openflow switch, the switch is
capable of figuring out if two ports belong to same vlan or not?
2.also can vlans be implemented as group tables?
code snippet as below:
def _handle_PacketIn (self,event):
> # event handler for incoming packets.check
> pox/openflow/__init__.py for infor on PacketIn(Event) class
> # ofp represents the real openflow packet which triggered the
> event and is an event attribute.
> parsedpkt = event.parsed
> inport = event.ofp.in_port
> data = event.ofp.data
> ethpkt = parsedpkt.find('ethernet')
> dstmacaddr = ethpkt.dst
> srcmacaddr = ethpkt.src
> #updating srcmactable
> self.updateMap(inport,srcmacaddr)
> #updating vlanport info
> self.setVlanID(inport)
> # processing the packet
> self.processPacket(dstmacaddr,inport,event,parsedpkt)
> def floodPacket(self,event):
> message = of.ofp_packet_out()
>
> message.actions.append(of.ofp_action_output(port=of.OFPP_FLOOD))
> message.data = event.data
> message.in_port = event.port
> return message
> def dropPacket(self,event):
> message = of.ofp_packet_out()
> #message.actions.append(of.ofp_action_output(port =
> of.OFPP_NONE))
> message.data = event.data
> message.in_port = event.port
> return message
> def updateMap(self,srcportin,srcmacaddr): # to update the
> mac-addr, port table
> self.macaddrtable[srcmacaddr] = srcportin
>
>
>
>
> * def setVlanID(self,anyport): if anyport % 2 ==
> 0: self.vlanporttable[anyport] = 2
> else:** self.vlanporttable[anyport] = 3*
> print self.vlanporttable
> def processPacket(self,destmacaddr,srcport,event,packet):# frame
> flow entries to forward the packets based on entries made in macaddrtable
> if destmacaddr.is_multicast: # if mulicast packet, then
> flood
> msg = self.floodPacket(event)
> elif destmacaddr in self.macaddrtable.keys():
> msg = of.ofp_flow_mod()
> log.debug ("%s"%msg)
> destport = self.macaddrtable[destmacaddr] # if
> dest mac addr in macaddr table, update the dest id
>
> * destvlanid = self.vlanporttable[destport]**
> srcvlanid = self.vlanporttable[srcport]*
> if (destport != srcport) and (destvlanid ==
> srcvlanid): # if src and dest ports in same vlan , then insert a match
> msg.match =
> of.ofp_match.from_packet(packet,event.port)
> log.debug ("%s" %msg)
>
> msg.actions.append(of.ofp_action_output(port=destport))
> *
> msg.actions.append(of.ofp_action_vlan_vid(vlan_vid = srcvlanid))*
> log.debug("%s" %msg)
> elif (destport == srcport) or (destvlanid !=
> srcvlanid): #elif destport is same as srcport drop the packet
> msg = self.dropPacket(event)
> elif destmacaddr not in self.macaddrtable.keys(): # if the
> destmac aaadr has no entry in macaddr table,bc the packet.
> msg = self.floodPacket(event)
> self.sendFlowMod(msg,event)
> def sendFlowMod(self,msg,event):
> event.connection.send(msg)
Cheers!
Durga
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.noxrepo.org/pipermail/pox-dev-noxrepo.org/attachments/20131105/412ccd67/attachment.htm>
More information about the pox-dev
mailing list