Added mpls testcase
diff --git a/accton/accton_util.py b/accton/accton_util.py
index 9ac96c8..1eb2946 100755
--- a/accton/accton_util.py
+++ b/accton/accton_util.py
@@ -388,7 +388,33 @@
     logging.info("Add port table, match port %lx" % 0x10000)
     ctrl.message_send(request)
     
-    
+
+def pop_vlan_flow(ctrl, ports, vlan_id=1):
+    # table 10: vlan
+    # goto to table 20
+    msgs=[]
+    for of_port in ports:
+            match = ofp.match()
+            match.oxm_list.append(ofp.oxm.in_port(of_port))
+            match.oxm_list.append(ofp.oxm.vlan_vid(0x1000+vlan_id))
+            request = ofp.message.flow_add(
+                table_id=10,
+                cookie=42,
+                match=match,
+                instructions=[
+                  ofp.instruction.apply_actions(
+                    actions=[
+                      ofp.action.pop_vlan()
+                    ]
+                  ),
+                  ofp.instruction.goto_table(20)
+                ],
+                priority=0)
+            logging.info("Add vlan %d tagged packets on port %d and go to table 20" %( vlan_id, of_port))
+            ctrl.message_send(request)
+
+
+    return msgs
 
 def add_vlan_table_flow(ctrl, ports, vlan_id=1, flag=VLAN_TABLE_FLAG_ONLY_BOTH, send_barrier=False):
     # table 10: vlan
@@ -404,6 +430,11 @@
                 cookie=42,
                 match=match,
                 instructions=[
+                  ofp.instruction.apply_actions(
+                    actions=[
+                      ofp.action.pop_vlan()
+                    ]
+                  ),
                   ofp.instruction.goto_table(20)
                 ],
                 priority=0)
@@ -698,7 +729,39 @@
         do_barrier(ctrl)   
 
     return request        
-        
+
+def add_mpls_flow(ctrl, action_group_id, label=100 ,ethertype=0x0800, bos=True, send_barrier=False):
+    match = ofp.match()
+    match.oxm_list.append(ofp.oxm.eth_type(0x8847))
+    match.oxm_list.append(ofp.oxm.mpls_label(label))
+    match.oxm_list.append(ofp.oxm.mpls_bos(bos))
+    actions = [ofp.action.dec_mpls_ttl(),
+               ofp.action.copy_ttl_in(),
+               ofp.action.pop_mpls(ethertype)]
+    request = ofp.message.flow_add(
+            table_id=24,
+            cookie=43,
+            match=match,
+            instructions=[
+                    ofp.instruction.apply_actions(
+                        actions=actions
+                    ),
+                    ofp.instruction.write_actions(
+                        actions=[ofp.action.group(action_group_id)]),
+                    ofp.instruction.goto_table(60)
+                ],
+            buffer_id=ofp.OFP_NO_BUFFER,
+            priority=1)
+
+    logging.info("Inserting MPLS flow , label %ld", label)
+    ctrl.message_send(request)
+
+    if send_barrier:
+        do_barrier(ctrl)
+
+    return request
+
+
 def add_mcast4_routing_flow(ctrl, vlan_id, src_ip, src_ip_mask, dst_ip, action_group_id, send_barrier=False):
     match = ofp.match()
     match.oxm_list.append(ofp.oxm.eth_type(0x0800))
diff --git a/accton/group_test.py b/accton/group_test.py
index 8acb025..84fbde4 100755
--- a/accton/group_test.py
+++ b/accton/group_test.py
@@ -620,7 +620,7 @@
                                                           oam_lm_tx_count=False,

                                                           set_pri_from_table=False

                                                           )

-            

+        mpls_intf_msg.group_id

         stats = get_stats(self, ofp.message.group_desc_stats_request())

         

         verify_group_stats=[]

diff --git a/ofdpa/onos.py b/ofdpa/onos.py
index bdc1e13..608ae6f 100644
--- a/ofdpa/onos.py
+++ b/ofdpa/onos.py
@@ -10,13 +10,23 @@
 8) MTU 4500
 """
 
-import logging
-
 from oftest import config
-import oftest.base_tests as base_tests
 import ofp
 from oftest.testutils import *
+from accton.accton_util import add_mpls_flow
 from accton_util import *
+import src.python.oftest.testutils
+from src.python.oftest.testutils import do_barrier
+from src.python.oftest.testutils import delete_all_flows
+from src.python.oftest.testutils import delete_all_groups
+from src.python.oftest.testutils import simple_tcp_packet
+from src.python.oftest.testutils import verify_packet_in
+from src.python.oftest.testutils import verify_no_other_packets
+from src.python.oftest.testutils import verify_no_packet
+from src.python.oftest.testutils import verify_packets
+from src.python.oftest.testutils import verify_packet
+from src.python.oftest.testutils import mpls_packet
+
 
 class PacketInSrcMacMiss(base_tests.SimpleDataPlane):
     """
@@ -292,14 +302,14 @@
     Port1(vid=in_port, src=00:00:00:22:22:in_port, 192.168.outport.1) , 
     Port2(vid=outport, dst=00:00:00:22:22:outport, 192.168.outport.1)
     """
-    def runTest(self):          
+    def runTest(self):
         delete_all_flows(self.controller)
         delete_all_groups(self.controller)
 
         if len(config["port_map"]) <2:
             logging.info("Port count less than 2, can't run this case")
             return
-        
+
         intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
         dst_mac=[0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
         dip=0xc0a80001
@@ -313,16 +323,16 @@
             #add vlan flow table
             add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_BOTH)
             #add termination flow
-            add_termination_flow(self.controller, port, 0x0800, intf_src_mac, vlan_id)           
+            add_termination_flow(self.controller, port, 0x0800, intf_src_mac, vlan_id)
             #add unicast routing flow
-            dst_ip = dip + (vlan_id<<8)           
+            dst_ip = dip + (vlan_id<<8)
             add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0, l3_msg.group_id)
             #add entries in the Bridging table to avoid packet-in from mac learning
             group_id = encode_l2_interface_group_id(vlan_id, port)
             add_bridge_flow(self.controller, dst_mac, vlan_id, group_id, True)
-        
-        do_barrier(self.controller)  
-        
+
+        do_barrier(self.controller)
+
         switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
         for in_port in ports:
             mac_src='00:00:00:22:22:%02X' % in_port
@@ -333,23 +343,23 @@
                 ip_dst='192.168.%02d.1' % out_port
                 parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=in_port,
                     eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src,
-                    ip_dst=ip_dst)            
+                    ip_dst=ip_dst)
                 pkt=str(parsed_pkt)
                 self.dataplane.send(in_port, pkt)
                 #build expected packet
                 mac_dst='00:00:00:22:22:%02X' % out_port
-                exp_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=out_port, 
+                exp_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=out_port,
                                        eth_dst=mac_dst, eth_src=switch_mac, ip_ttl=63,
                                        ip_src=ip_src, ip_dst=ip_dst)
                 pkt=str(exp_pkt)
                 verify_packet(self, pkt, out_port)
                 verify_no_other_packets(self)
 
-class L3VPNMPLS(base_tests.SimpleDataPlane): 
-	'''
-	Insert IP packet
-	Receive MPLS packet
-	'''
+class L3VPNMPLS(base_tests.SimpleDataPlane):
+    """
+	    Insert IP packet
+	    Receive MPLS packet
+    """
     def runTest(self):
         delete_all_flows(self.controller)
         delete_all_groups(self.controller)
@@ -371,7 +381,7 @@
             #add MPLS interface group
             mpls_gid, mpls_msg = add_mpls_intf_group(self.controller, l2_gid, dst_mac, intf_src_mac, vlan_id, port)
             #add MPLS L3 VPN group
-            mpls_label_gid, mpls_label_msg = add_mpls_label_group(self.controller, subtype=OFDPA_MPLS_GROUP_SUBTYPE_L3_VPN_LABEL, 
+            mpls_label_gid, mpls_label_msg = add_mpls_label_group(self.controller, subtype=OFDPA_MPLS_GROUP_SUBTYPE_L3_VPN_LABEL,
 		     index=port, ref_gid= mpls_gid, push_mpls_header=True, set_mpls_label=port, set_bos=1, set_ttl=32)
             #add vlan flow table
             add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_BOTH)
@@ -402,8 +412,68 @@
                 #build expect packet
                 mac_dst='00:00:00:22:22:%02X' % out_port
                 label = (out_port, 0, 1, 32)
-                exp_pkt = mpls_packet(dl_vlan_enable=True, vlan_vid=out_port, ip_ttl=64, ip_src=ip_src, 
+                exp_pkt = mpls_packet(dl_vlan_enable=True, vlan_vid=out_port, ip_ttl=64, ip_src=ip_src,
                             ip_dst=ip_dst, eth_dst=mac_dst, eth_src=switch_mac, label=[label])
                 pkt=str(exp_pkt)
                 verify_packet(self, pkt, out_port)
                 verify_no_other_packets(self)
+
+class MplsTermination(base_tests.SimpleDataPlane):
+    '''
+	Insert IP packet
+	Receive MPLS packet
+    '''
+    def runTest(self):
+        delete_all_flows(self.controller)
+        delete_all_groups(self.controller)
+
+        if len(config["port_map"]) <2:
+            logging.info("Port count less than 2, can't run this case")
+            return
+
+        intf_src_mac=[0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
+        dst_mac=[0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
+        dip=0xc0a80001
+        index=1
+        ports = config["port_map"].keys()
+        for port in ports:
+            #add l2 interface group
+            vlan_id=port
+            l2_gid, l2_msg = add_one_l2_interface_grouop(self.controller, port, vlan_id, True, False)
+            dst_mac[5]=vlan_id
+            #add L3 Unicast  group
+            l3_msg=add_l3_unicast_group(self.controller, port, vlanid=vlan_id, id=vlan_id, src_mac=intf_src_mac, dst_mac=dst_mac)
+            #add vlan flow table
+            add_one_vlan_table_flow(self.controller, port, vlan_id, flag=VLAN_TABLE_FLAG_ONLY_BOTH)
+            #add termination flow
+            add_termination_flow(self.controller, port, 0x0800, intf_src_mac, vlan_id)
+            #add routing flow
+            dst_ip = dip + (vlan_id<<8)
+            add_mpls_flow(self.controller, l3_msg.group_id, port)
+            #add entries in the Bridging table to avoid packet-in from mac learning
+            group_id = encode_l2_interface_group_id(vlan_id, port)
+            add_bridge_flow(self.controller, dst_mac, vlan_id, group_id, True)
+
+        do_barrier(self.controller)
+
+        switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
+        for in_port in ports:
+            mac_src='00:00:00:22:22:%02X' % in_port
+            ip_src='192.168.%02d.1' % in_port
+            for out_port in ports:
+                if in_port == out_port:
+                     continue
+                ip_dst='192.168.%02d.1' % out_port
+                parsed_pkt = simple_tcp_packet(pktlen=100, dl_vlan_enable=True, vlan_vid=in_port,
+                    eth_dst=switch_mac, eth_src=mac_src, ip_ttl=64, ip_src=ip_src,
+                    ip_dst=ip_dst)
+                pkt=str(parsed_pkt)
+                self.dataplane.send(in_port, pkt)
+                #build expect packet
+                mac_dst='00:00:00:22:22:%02X' % out_port
+                label = (out_port, 0, 1, 32)
+                exp_pkt = mpls_packet(dl_vlan_enable=True, vlan_vid=out_port, ip_ttl=64, ip_src=ip_src,
+                            ip_dst=ip_dst, eth_dst=mac_dst, eth_src=switch_mac, label=[label])
+                pkt=str(exp_pkt)
+                verify_packet(self, pkt, out_port)
+                verify_no_other_packets(self)
\ No newline at end of file