Added Multicast tests and fixed Untag flow rules
diff --git a/accton/accton_util.py b/accton/accton_util.py
index 155849f..aeff03f 100755
--- a/accton/accton_util.py
+++ b/accton/accton_util.py
@@ -444,7 +444,7 @@
         if (flag == VLAN_TABLE_FLAG_ONLY_UNTAG) or (flag == VLAN_TABLE_FLAG_ONLY_BOTH):
             match = ofp.match()
             match.oxm_list.append(ofp.oxm.in_port(of_port))
-            match.oxm_list.append(ofp.oxm.vlan_vid_masked(0, 0xfff))
+            match.oxm_list.append(ofp.oxm.vlan_vid_masked(0, 0x1fff))
             request = ofp.message.flow_add(
                 table_id=10,
                 cookie=42,
@@ -452,7 +452,7 @@
                 instructions=[
                   ofp.instruction.apply_actions(
                     actions=[
-                      ofp.action.set_field(ofp.oxm.vlan_vid(0x1000+vlan_id))
+                      ofp.action.set_field(ofp.oxm.vlan_vid(vlan_id))
                     ]
                   ),
                   ofp.instruction.goto_table(20)
@@ -548,65 +548,13 @@
     logging.info("Add allow all vlan on port %d " %(in_port))
     ctrl.message_send(request)    
 
-def add_untag_vlan_table(ctrl, in_port,vlan_id=0x0000, send_barrier=False):
-    """it a flow to allow all vlan untag on this port"""
-    match = ofp.match()
-    match.oxm_list.append(ofp.oxm.in_port(in_port))
-    match.oxm_list.append(ofp.oxm.vlan_vid(vlan_id))
-    actions=[]
-    #actions.append(ofp.action.push_vlan(0x8100))
-    actions.append(ofp.action.set_field(ofp.oxm.vlan_vid(0x100a)))
-    request = ofp.message.flow_add(
-        table_id=10,
-        cookie=42,
-        match=match,
-        instructions=[
-            ofp.instruction.apply_actions(
-                actions=actions
-            ),
-            ofp.instruction.goto_table(20)
-        ],
-        priority=0)
-    logging.info("Add allow all untag on port %d " %(in_port))
-    print "REQUEST:"
-    print request.show()
-    print "END"
-
-    ctrl.message_send(request)
-
-def add_untag_vlan_table_flow(ctrl, in_port,vlan_id=0x1001, vlan_mask=0x1fff, send_barrier=False):
-    """it a flow to allow all vlan untag on this port"""
-    match = ofp.match()
-    match.oxm_list.append(ofp.oxm.in_port(in_port))
-    match.oxm_list.append(ofp.oxm.vlan_vid_masked(vlan_id, vlan_mask))
-    actions=[]
-    #actions.append(ofp.action.push_vlan(0x8100))
-    actions.append(ofp.action.set_field(ofp.oxm.vlan_vid(0x100a)))
-    request = ofp.message.flow_add(
-        table_id=10,
-        cookie=42,
-        match=match,
-        instructions=[
-            ofp.instruction.apply_actions(
-                actions=actions
-            ),
-            ofp.instruction.goto_table(20)
-        ],
-        priority=0)
-    logging.info("Add allow all untag on port %d " %(in_port))
-    print "REQUEST:"
-    print request.show()
-    print "END"
-
-    ctrl.message_send(request)
-    
 def add_one_vlan_table_flow(ctrl, of_port, vlan_id=1, vrf=0, flag=VLAN_TABLE_FLAG_ONLY_BOTH, send_barrier=False):
     # table 10: vlan
     # goto to table 20
     if (flag == VLAN_TABLE_FLAG_ONLY_TAG) or (flag == VLAN_TABLE_FLAG_ONLY_BOTH):
         match = ofp.match()
         match.oxm_list.append(ofp.oxm.in_port(of_port))
-        match.oxm_list.append(ofp.oxm.vlan_vid(0x1000+vlan_id))
+        match.oxm_list.append(ofp.oxm.vlan_vid_masked(0x1000+vlan_id,0x1fff))
 
         actions=[]
         if vrf!=0:
@@ -631,13 +579,13 @@
     if (flag == VLAN_TABLE_FLAG_ONLY_UNTAG) or (flag == VLAN_TABLE_FLAG_ONLY_BOTH):
         match = ofp.match()
         match.oxm_list.append(ofp.oxm.in_port(of_port))
-        match.oxm_list.append(ofp.oxm.vlan_vid(0))
+        match.oxm_list.append(ofp.oxm.vlan_vid_masked(0, 0x1fff))
         
         actions=[]
         if vrf!=0:
             actions.append(ofp.action.set_field(ofp.oxm.exp2ByteValue(exp_type=1, value=vrf)))
             
-        actions.append(ofp.action.set_field(ofp.oxm.vlan_vid(0x1000+vlan_id)))
+        actions.append(ofp.action.set_field(ofp.oxm.vlan_vid(vlan_id)))
         
         request = ofp.message.flow_add(
             table_id=10,
diff --git a/ofdpa/dev.py b/ofdpa/dev.py
index b5140b4..46608c1 100644
--- a/ofdpa/dev.py
+++ b/ofdpa/dev.py
@@ -40,7 +40,7 @@
     def runTest(self):
         do_barrier(self.controller)
         for port in config["port_map"].keys():
-            add_one_vlan_table_flow(self.controller, port, 10)
+            add_one_vlan_table_flow(self.controller, port, 10, flag=VLAN_TABLE_FLAG_ONLY_BOTH)
             do_barrier(self.controller)
             logging.info("Sending flow stats request")
             stats = get_flow_stats(self, ofp.match())
@@ -50,6 +50,7 @@
             print "END"
         do_barrier(self.controller)
         verify_no_other_packets(self)
+
 @disabled
 class UnTagFlow0(base_tests.SimpleDataPlane):
     def runTest(self):
@@ -66,6 +67,7 @@
         do_barrier(self.controller)
         verify_no_other_packets(self)
 
+@disabled
 class UnTagFlow10(base_tests.SimpleDataPlane):
     def runTest(self):
         do_barrier(self.controller)
diff --git a/ofdpa/onos.py b/ofdpa/onos.py
index abee77a..86c7053 100644
--- a/ofdpa/onos.py
+++ b/ofdpa/onos.py
@@ -770,9 +770,9 @@
                 verify_packet(self, pkt, out_port)
                 verify_no_other_packets(self)
 
-class L3McastRoute(base_tests.SimpleDataPlane):
+class L3McastToL2(base_tests.SimpleDataPlane):
     """
-    Mcast routing
+    Mcast routing to L2
     """
     def runTest(self):
         """
@@ -808,7 +808,7 @@
         for port in config["port_map"].keys():
             if port == port2:
                 continue
-            l2_intf_gid, msg=add_one_l2_interface_group(self.controller, port, vlan_id=vlan_id, is_tagged=False, send_barrier=False)
+            l2_intf_gid, msg=add_one_l2_interface_group(self.controller, port, vlan_id=vlan_id, is_tagged=True, send_barrier=False)
             l2_intf_group_list.append(l2_intf_gid)
             #add vlan flow table
             add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG)
@@ -829,9 +829,159 @@
         pkt=str(parsed_pkt)
         self.dataplane.send(port1, pkt)
         for port in config["port_map"].keys():
-            if port == port2:
+            if port == port2 or port == port1:
                  verify_no_packet(self, pkt, port)
+                 continue
             verify_packet(self, pkt, port)
         verify_no_other_packets(self)
 
+class L3McastToL3(base_tests.SimpleDataPlane):
+    """
+    Mcast routing
+    """
+    def runTest(self):          
+        """
+        port1 (vlan 1)-> port 2 (vlan 2)
+        """
+        delete_all_flows(self.controller)
+        delete_all_groups(self.controller)
+
+        if len(config["port_map"]) <3:
+            logging.info("Port count less than 2, can't run this case")
+            return
+
+        vlan_id =1
+        port2_out_vlan=2
+        port3_out_vlan=3
+        in_vlan=1 #macast group vid shall use input vlan diffe from l3 interface use output vlan        
+        intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
+        intf_src_mac_str=':'.join(['%02X' % x for x in intf_src_mac])        
+        dst_mac=[0x01, 0x00, 0x5e, 0x01, 0x01, 0x01]
+        dst_mac_str=':'.join(['%02X' % x for x in dst_mac])
+        port1_mac=[0x00, 0x11, 0x11, 0x11, 0x11, 0x11]
+        port1_mac_str=':'.join(['%02X' % x for x in port1_mac])
+        src_ip=0xc0a80101
+        src_ip_str="192.168.1.1"
+        dst_ip=0xe0010101
+        dst_ip_str="224.1.1.1"
+        
+        port1=config["port_map"].keys()[0]
+        port2=config["port_map"].keys()[1]
+        port3=config["port_map"].keys()[2]
+
+        #add l2 interface group
+        for port in config["port_map"].keys():        
+            add_one_l2_interface_group(self.controller, port, vlan_id=vlan_id, is_tagged=False, send_barrier=False)
+            #add vlan flow table
+            add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG)          
+            vlan_id +=1            
+
+        #add termination flow
+        add_termination_flow(self.controller, port1, 0x0800, [0x01, 0x00, 0x5e, 0x00, 0x00, 0x00], vlan_id)
+
+        #add l3 interface group
+        port2_ucast_msg=add_l3_interface_group(self.controller, port2, port2_out_vlan, 2, intf_src_mac)
+        port3_ucast_msg=add_l3_interface_group(self.controller, port3, port3_out_vlan, 3, intf_src_mac)        
+        mcat_group_msg=add_l3_mcast_group(self.controller, in_vlan,  2, [port2_ucast_msg.group_id, port3_ucast_msg.group_id])
+        add_mcast4_routing_flow(self.controller, in_vlan, src_ip, 0, dst_ip, mcat_group_msg.group_id)               
+        
+        parsed_pkt = simple_udp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=1,
+                                       eth_dst=dst_mac_str,
+                                       eth_src=port1_mac_str,
+                                       ip_ttl=64,
+                                       ip_src=src_ip_str,
+                                       ip_dst=dst_ip_str)
+        pkt=str(parsed_pkt)
+        self.dataplane.send(port1, pkt)            
+        parsed_pkt = simple_udp_packet(pktlen=96, 
+                                       eth_dst=dst_mac_str,
+                                       eth_src=intf_src_mac_str,
+                                       ip_ttl=63,
+                                       ip_src=src_ip_str,
+                                       ip_dst=dst_ip_str)
+        pkt=str(parsed_pkt)            
+        verify_packet(self, pkt, port2)
+        verify_packet(self, pkt, port3)        
+        verify_no_other_packets(self)  
+
+class L3McastToVPN(base_tests.SimpleDataPlane):
+    """
+    Mcast routing
+    """
+    def runTest(self):
+        """
+        port1 (vlan 1)-> port 2 (vlan 2)
+        """
+        #delete_all_flows(self.controller)
+        #delete_all_groups(self.controller)
+
+        if len(config["port_map"]) <3:
+            logging.info("Port count less than 2, can't run this case")
+            return
+
+        vlan_id =1
+        port2_out_vlan=2
+        port3_out_vlan=3
+        in_vlan=1 #macast group vid shall use input vlan diffe from l3 interface use output vlan
+        intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
+        intf_src_mac_str=':'.join(['%02X' % x for x in intf_src_mac])
+        dst_mac=[0x01, 0x00, 0x5e, 0x01, 0x01, 0x01]
+        dst_mac_str=':'.join(['%02X' % x for x in dst_mac])
+        port1_mac=[0x00, 0x11, 0x11, 0x11, 0x11, 0x11]
+        port1_mac_str=':'.join(['%02X' % x for x in port1_mac])
+        src_ip=0xc0a80101
+        src_ip_str="192.168.1.1"
+        dst_ip=0xe0010101
+        dst_ip_str="224.1.1.1"
+
+        port1=config["port_map"].keys()[0]
+        port2=config["port_map"].keys()[1]
+        port3=config["port_map"].keys()[2]
+
+        #add l2 interface group
+        for port in config["port_map"].keys():
+            add_one_l2_interface_group(self.controller, port, vlan_id=vlan_id, is_tagged=False, send_barrier=False)
+            #add vlan flow table
+            add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_TAG)
+            vlan_id +=1
+
+        #add termination flow
+        add_termination_flow(self.controller, port1, 0x0800, [0x01, 0x00, 0x5e, 0x00, 0x00, 0x00], vlan_id)
+
+        #add MPLS interface group
+        l2_gid = encode_l2_interface_group_id(port2_out_vlan, port2)
+        mpls_gid2, mpls_msg = add_mpls_intf_group(self.controller, l2_gid, dst_mac, intf_src_mac, port2_out_vlan, port2)
+        l2_gid3 = encode_l2_interface_group_id(port3_out_vlan, port3)
+        mpls_gid3, mpls_msg = add_mpls_intf_group(self.controller, l2_gid3, dst_mac, intf_src_mac, port3_out_vlan, port3)
+        #add L3VPN groups
+        mpls_label_gid2, mpls_label_msg = add_mpls_label_group(self.controller, subtype=OFDPA_MPLS_GROUP_SUBTYPE_L3_VPN_LABEL,
+                     index=(0x20000+port2), ref_gid= mpls_gid2, push_mpls_header=True, set_mpls_label=port2, set_bos=1, cpy_ttl_outward=True)
+        mpls_label_gid3, mpls_label_msg = add_mpls_label_group(self.controller, subtype=OFDPA_MPLS_GROUP_SUBTYPE_L3_VPN_LABEL,
+                     index=(0x10000+port3), ref_gid= mpls_gid3, push_mpls_header=True, set_mpls_label=port3, set_bos=1, cpy_ttl_outward=True)
+
+
+
+        mcat_group_msg=add_l3_mcast_group(self.controller, in_vlan,  2, [0x92020022 , 0x92010023])
+        add_mcast4_routing_flow(self.controller, in_vlan, src_ip, 0, dst_ip, mcat_group_msg.group_id)
+
+        parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=1,
+                                       eth_dst=dst_mac_str,
+                                       eth_src=port1_mac_str,
+                                       ip_ttl=64,
+                                       ip_src=src_ip_str,
+                                       ip_dst=dst_ip_str)
+        pkt=str(parsed_pkt)
+        self.dataplane.send(port1, pkt)
+        label = (in_vlan, 0, 1, 63)
+        parsed_pkt = mpls_packet(pktlen=100,
+                                       eth_dst=dst_mac_str,
+                                       eth_src=intf_src_mac_str,
+                                       ip_ttl=63,
+                                       ip_src=src_ip_str, label= [label],
+                                       ip_dst=dst_ip_str)
+        pkt=str(parsed_pkt)
+        verify_packet(self, pkt, port2)
+        verify_packet(self, pkt, port3)
+        verify_no_other_packets(self)
+