Xpliant switch type support added

Change-Id: I02f71e8b8e5ce21dff0f946dbb4937735ed3fd77
diff --git a/accton/accton_util.py b/accton/accton_util.py
index 9a0638b..fd9d1fe 100755
--- a/accton/accton_util.py
+++ b/accton/accton_util.py
@@ -717,8 +717,8 @@
         match.oxm_list.append(ofp.oxm.vlan_vid_masked(0x1000+vlan_id,0x1fff))
 
         actions=[]
-        if vrf!=0:
-            actions.append(ofp.action.set_field(ofp.oxm.exp2ByteValue(exp_type=1, value=vrf))) 
+        if config["switch_type"] != 'xpliant' and 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(value=vlan_id)))
 
@@ -1092,10 +1092,10 @@
 
     return request
 
-def add_unicast_routing_flow(ctrl, eth_type, dst_ip, mask, action_group_id, vrf=0, send_ctrl=False, send_barrier=False):
+def add_unicast_routing_flow(ctrl, eth_type, dst_ip, mask, action_group_id, vrf=0, send_ctrl=False, send_barrier=False, priority = 1):
     match = ofp.match()
     match.oxm_list.append(ofp.oxm.eth_type(eth_type))
-    if vrf != 0:
+    if config["switch_type"] != 'xpliant' and vrf != 0:
         match.oxm_list.append(ofp.oxm.exp2ByteValue(ofp.oxm.OFDPA_EXP_TYPE_VRF, vrf))
 
     match.oxm_list.append(ofp.oxm.ipv4_dst_masked(dst_ip, mask))
@@ -1116,7 +1116,7 @@
             match=match,
             instructions=instructions,
             buffer_id=ofp.OFP_NO_BUFFER,
-            priority=1)
+            priority=priority)
 
     logging.info("Inserting unicast routing flow eth_type %lx, dip %ld",eth_type, dst_ip)
     ctrl.message_send(request)
@@ -1194,6 +1194,34 @@
 
     return request
 
+def xpliant_add_mpls_flow(ctrl, action_group_id=0x0, label=100 ,ethertype=0x0800, bos=1, vrf=1, goto_table=27, send_barrier=False):
+    match = ofp.match()
+    match.oxm_list.append(ofp.oxm.eth_type(0x8847))
+    match.oxm_list.append(ofp.oxm.mpls_label(label))
+
+    apply_actions = []
+    apply_actions.append(ofp.action.group(action_group_id))
+    apply_actions.append(ofp.action.dec_mpls_ttl())
+    if (goto_table != 29):
+        apply_actions.append(ofp.action.pop_mpls(ethertype))
+
+    request = ofp.message.flow_add(
+            table_id=24,
+            cookie=43,
+            match=match,
+            instructions=[
+                    ofp.instruction.apply_actions(actions=apply_actions),
+                ],
+            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_mpls_flow_pw(ctrl, action_group_id, label, ethertype, bos, tunnel_index, goto_table=MPLS_TYPE_FLOW_TABLE, popMPLS=True, popL2=False, of_port=0, send_barrier=False):
     match = ofp.match()
     match.oxm_list.append(ofp.oxm.eth_type(0x8847))
@@ -1237,7 +1265,7 @@
 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))
-    match.oxm_list.append(ofp.oxm.vlan_vid(vlan_id))
+    match.oxm_list.append(ofp.oxm.vlan_vid(0x1000 + vlan_id))
     if src_ip_mask!=0:
         match.oxm_list.append(ofp.oxm.ipv4_src_masked(src_ip, src_ip_mask))
     else:
diff --git a/ofdpa/flows.py b/ofdpa/flows.py
index 9c6c5aa..d13a4c3 100755
--- a/ofdpa/flows.py
+++ b/ofdpa/flows.py
@@ -1736,7 +1736,10 @@
                 else:
                     add_termination_flow( self.controller, port, 0x8847, intf_src_mac, vlan_id, goto_table=24 )
                 #add_mpls_flow( self.controller, ecmp_gid, port, goto_table=29 )
-                add_mpls_flow( self.controller, mpls_label_gid, mpls_label, goto_table=29 )
+                if config["switch_type"] != 'xpliant':
+                    add_mpls_flow( self.controller, mpls_label_gid, mpls_label, goto_table=29 )
+                else:
+                    xpliant_add_mpls_flow( self.controller, mpls_label_gid, mpls_label, goto_table=29 )
                 dst_ip = dip + (vlan_id << 8)
                 Groups._put( l2_gid )
                 Groups._put( mpls_gid )
@@ -1812,7 +1815,12 @@
                     add_termination_flow( self.controller, 0, 0x8847, intf_src_mac, vlan_id, goto_table=24 )
                 else:
                     add_termination_flow( self.controller, port, 0x8847, intf_src_mac, vlan_id, goto_table=24 )
-                add_mpls_flow( self.controller, ecmp_msg.group_id, mpls_label )
+
+                if config["switch_type"] != 'xpliant':
+                    add_mpls_flow( self.controller, ecmp_msg.group_id, mpls_label )
+                else:
+                    xpliant_add_mpls_flow( self.controller, ecmp_msg.group_id, mpls_label )
+
                 # add_mpls_flow(self.controller, label=port)
                 dst_ip = dip + (vlan_id << 8)
                 # add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0xffffff00,
@@ -1842,8 +1850,12 @@
                     self.dataplane.send( in_port, pkt )
                     # build expect packet
                     mac_dst = '00:00:00:22:22:%02X' % (out_port)
+                    if config["switch_type"] != 'xpliant':
+                        ip_ttl=31
+                    else:
+                        ip_ttl=64
                     exp_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=(out_vlan_vid),
-                            eth_dst=mac_dst, eth_src=switch_mac, ip_ttl=31, ip_src=ip_src, ip_dst=ip_dst )
+                            eth_dst=mac_dst, eth_src=switch_mac, ip_ttl=ip_ttl, ip_src=ip_src, ip_dst=ip_dst )
                     pkt = str( exp_pkt )
                     verify_packet( self, pkt, out_port )
                     verify_no_other_packets( self )
@@ -2020,7 +2032,7 @@
                     add_termination_flow( self.controller, port, 0x0800, intf_src_mac, vlan_id )
                 # add unicast routing flow
                 dst_ip = dip + (vlan_id << 8)
-                add_unicast_routing_flow( self.controller, 0x0800, dst_ip, 0xffffffff, l3_msg.group_id )
+                add_unicast_routing_flow( self.controller, 0x0800, dst_ip, 0xffffffff, l3_msg.group_id, priority=2 )
                 Groups.put( l2gid )
                 Groups.put( l3_msg.group_id )
             l3_gid = encode_l3_unicast_group_id( ports[ 0 ] )
@@ -2289,9 +2301,11 @@
             exp_pkt = simple_tcp_packet( pktlen=100, dl_vlan_enable=True, vlan_vid=ports[ 0 ],
                                          eth_dst=mac_dst, eth_src=switch_mac, ip_ttl=63, ip_src=ip_src,
                                          ip_dst=ip_dst,tcp_dport=tcp )
-            pkt = str( exp_pkt )
-            verify_packet( self, pkt, ports[ 0 ] )
-            verify_no_other_packets( self )
+            # Expects packet on the input port
+            if config["switch_type"] != 'xpliant':
+                pkt = str( exp_pkt )
+                verify_packet( self, pkt, ports[ 0 ] )
+                verify_no_other_packets( self )
 
             # third part of the test - edit the group to completely remove bucket. Packet sent
             # should be dropped by the switch
@@ -2313,7 +2327,7 @@
             # original egress port, and verify packet is received on egress switch port
             l3_gid = encode_l3_unicast_group_id( ports[ 1 ] )
             mod_l3_ecmp_group( self.controller, ports[ 0 ], [ l3_gid ] )
-            time.sleep(0.1)
+            do_barrier(self.controller)
             in_port = ports[0]
             out_port = ports[1]
             logging.info("Sending packet to port: " + str(in_port) + ", expected egress on port: " + str(out_port))