<div dir="ltr"><div class="gmail_default" style="font-family:tahoma,sans-serif;font-size:small;color:rgb(153,51,0)">Hello All,</div><div class="gmail_default" style="font-family:tahoma,sans-serif;font-size:small;color:rgb(153,51,0)">

<br></div><div class="gmail_default" style="font-family:tahoma,sans-serif;font-size:small;color:rgb(153,51,0)">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.</div>

<div class="gmail_default" style="font-family:tahoma,sans-serif;font-size:small;color:rgb(153,51,0)"><br></div><div class="gmail_default" style="font-family:tahoma,sans-serif;font-size:small;color:rgb(153,51,0)">Now, </div>

<div class="gmail_default" style="font-family:tahoma,sans-serif;font-size:small;color:rgb(153,51,0)"><a href="http://1.is">1.is</a> 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?</div>

<div class="gmail_default" style="font-family:tahoma,sans-serif;font-size:small;color:rgb(153,51,0)"><br></div><div class="gmail_default" style="font-family:tahoma,sans-serif;font-size:small;color:rgb(153,51,0)">2.also can vlans be implemented as group tables?</div>

<div class="gmail_default" style="font-family:tahoma,sans-serif;font-size:small;color:rgb(153,51,0)"><br></div><div class="gmail_default" style="font-family:tahoma,sans-serif;font-size:small;color:rgb(153,51,0)"><br></div>

<div class="gmail_default" style="font-family:tahoma,sans-serif;font-size:small;color:rgb(153,51,0)">code snippet as below:</div><div class="gmail_default" style="font-family:tahoma,sans-serif;font-size:small;color:rgb(153,51,0)">

<br></div><div class="gmail_default"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><font color="#000000" face="courier new, monospace" size="1">def _handle_PacketIn (self,event):<br>

</font><font color="#000000" face="courier new, monospace" size="1">         # event handler for incoming packets.check pox/openflow/__init__.py for infor on PacketIn(Event) class<br></font><font color="#000000" face="courier new, monospace" size="1">         # ofp represents the real openflow packet which triggered the event and is an event attribute.</font><font color="#000000" face="courier new, monospace" size="1"><br>

</font><font color="#000000" face="courier new, monospace" size="1">                parsedpkt = event.parsed<br></font><font color="#000000" face="courier new, monospace" size="1">                inport = event.ofp.in_port<br>

</font><font color="#000000" face="courier new, monospace" size="1">                data = event.ofp.data<br></font><font color="#000000" face="courier new, monospace" size="1">                ethpkt = parsedpkt.find('ethernet')<br>

</font><font color="#000000" face="courier new, monospace" size="1">                dstmacaddr = ethpkt.dst<br></font><font color="#000000" face="courier new, monospace" size="1">                srcmacaddr = ethpkt.src</font><font color="#000000" face="courier new, monospace" size="1"><br>

</font><font color="#000000" face="courier new, monospace" size="1">        #updating srcmactable<br></font><font color="#000000" face="courier new, monospace" size="1">                self.updateMap(inport,srcmacaddr)</font><font color="#000000" face="courier new, monospace" size="1"><br>

</font><font color="#000000" face="courier new, monospace" size="1">        #updating vlanport info<br></font><font color="#000000" face="courier new, monospace" size="1">                self.setVlanID(inport)<br></font><font color="#000000" face="courier new, monospace" size="1">        # processing the packet<br>

</font><font color="#000000" face="courier new, monospace" size="1">                self.processPacket(dstmacaddr,inport,event,parsedpkt)</font><font color="#000000" face="courier new, monospace" size="1"><br></font><font color="#000000" face="courier new, monospace" size="1">        def floodPacket(self,event):<br>

</font><font color="#000000" face="courier new, monospace" size="1">                message = of.ofp_packet_out()<br></font><font color="#000000" face="courier new, monospace" size="1">                message.actions.append(of.ofp_action_output(port=of.OFPP_FLOOD))<br>

</font><font color="#000000" face="courier new, monospace" size="1">                message.data = event.data<br></font><font color="#000000" face="courier new, monospace" size="1">                message.in_port = event.port<br>

</font><font color="#000000" face="courier new, monospace" size="1">                return message</font><font color="#000000" face="courier new, monospace" size="1"><br></font><font color="#000000" face="courier new, monospace" size="1">        def dropPacket(self,event):<br>

</font><font color="#000000" face="courier new, monospace" size="1">                message = of.ofp_packet_out()<br></font><font color="#000000" face="courier new, monospace" size="1">                #message.actions.append(of.ofp_action_output(port = of.OFPP_NONE))<br>

</font><font color="#000000" face="courier new, monospace" size="1">                message.data = event.data<br></font><font color="#000000" face="courier new, monospace" size="1">                message.in_port = event.port<br>

</font><font color="#000000" face="courier new, monospace" size="1">                return message</font><font color="#000000" face="courier new, monospace" size="1"><br></font><font color="#000000" face="courier new, monospace" size="1">        def updateMap(self,srcportin,srcmacaddr): # to update the mac-addr, port table<br>

</font><font color="#000000" face="courier new, monospace" size="1">                self.macaddrtable[srcmacaddr] = srcportin</font><font color="#000000" face="courier new, monospace" size="1"><br></font><b><font color="#000000" face="courier new, monospace" size="1">        def setVlanID(self,anyport):</font><font color="#000000" face="courier new, monospace" size="1"><br>

</font><font color="#000000" face="courier new, monospace" size="1">                if anyport % 2 == 0:<br></font><font color="#000000" face="courier new, monospace" size="1">                        self.vlanporttable[anyport] = 2<br>

</font><font color="#000000" face="courier new, monospace" size="1">                else:<br></font></b><font color="#000000" face="courier new, monospace" size="1"><b>                        self.vlanporttable[anyport] = 3</b><br>

</font><font color="#000000" face="courier new, monospace" size="1">                print self.vlanporttable<br></font><font color="#000000" face="courier new, monospace" size="1">        def processPacket(self,destmacaddr,srcport,event,packet):# frame flow entries to forward the packets based on entries made in macaddrtable</font><font color="#000000" face="courier new, monospace" size="1"><br>

</font><font color="#000000" face="courier new, monospace" size="1">                if destmacaddr.is_multicast: # if mulicast packet, then flood<br></font><font color="#000000" face="courier new, monospace" size="1">                        msg = self.floodPacket(event)</font><font color="#000000" face="courier new, monospace" size="1"><br>

</font><font color="#000000" face="courier new, monospace" size="1">                elif destmacaddr in self.macaddrtable.keys():<br></font><font color="#000000" face="courier new, monospace" size="1">                        msg = of.ofp_flow_mod()<br>

</font><font color="#000000" face="courier new, monospace" size="1">                        log.debug ("%s"%msg)<br></font><font color="#000000" face="courier new, monospace" size="1">                        destport = self.macaddrtable[destmacaddr] # if dest mac addr in macaddr table, update the dest id <br>

</font><font color="#000000" face="courier new, monospace" size="1"><b>                        destvlanid = self.vlanporttable[destport]<br></b></font><font color="#000000" face="courier new, monospace" size="1"><b>                        srcvlanid = self.vlanporttable[srcport]</b><br>

</font><font color="#000000" face="courier new, monospace" size="1">                        if (destport != srcport) and (destvlanid == srcvlanid): # if src and dest ports in same vlan , then insert a match<br></font><font color="#000000" face="courier new, monospace" size="1">                                msg.match = of.ofp_match.from_packet(packet,event.port)<br>

</font><font color="#000000" face="courier new, monospace" size="1">                                log.debug ("%s" %msg)<br></font><font color="#000000" face="courier new, monospace" size="1">                                msg.actions.append(of.ofp_action_output(port=destport))<br>

</font><font color="#000000" face="courier new, monospace" size="1">                              <b>  msg.actions.append(of.ofp_action_vlan_vid(vlan_vid = srcvlanid))</b><br></font><font color="#000000" face="courier new, monospace" size="1">                                log.debug("%s" %msg)<br>

</font><font color="#000000" face="courier new, monospace" size="1">                        elif (destport == srcport) or (destvlanid != srcvlanid): #elif destport is same as srcport drop the packet<br></font><font color="#000000" face="courier new, monospace" size="1">                                msg = self.dropPacket(event)</font><font color="#000000" face="courier new, monospace" size="1"><br>

</font><font color="#000000" face="courier new, monospace" size="1">                elif destmacaddr not in self.macaddrtable.keys(): # if the destmac aaadr has no entry in macaddr table,bc the packet.<br></font><font color="#000000" face="courier new, monospace" size="1">                        msg = self.floodPacket(event)<br>

</font><font color="#000000" face="courier new, monospace" size="1">                self.sendFlowMod(msg,event)</font><font color="#000000" face="courier new, monospace" size="1"><br></font><font color="#000000" face="courier new, monospace" size="1">        def sendFlowMod(self,msg,event):<br>

</font><font color="#000000" face="courier new, monospace" size="1">                event.connection.send(msg)</font></blockquote><div class="gmail_default"><div style="font-size:small;font-family:tahoma,sans-serif;color:rgb(153,51,0)">

<br></div></div></div><div class="gmail_default" style="font-family:tahoma,sans-serif;font-size:small;color:rgb(153,51,0)"><br></div><div>Cheers!<br>Durga<br><br></div>
</div>