Implemented MPLS FWD
diff --git a/accton/accton_util.py b/accton/accton_util.py
index 2f0cd35..d38bb78 100755
--- a/accton/accton_util.py
+++ b/accton/accton_util.py
@@ -779,7 +779,43 @@
return request
-def add_mpls_flow(ctrl, action_group_id, label=100 ,ethertype=0x0800, bos=1, vrf=1, send_barrier=False):
+def add_mpls(ctrl, action_group_id, label=100 ,ethertype=0x0800, bos=1, vrf=1, 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.set_field(ofp.oxm.exp2ByteValue(exp_type=1, value=vrf)),
+ ofp.action.set_field(ofp.oxm.exp2ByteValue(exp_type=23, value=32)),
+ ofp.action.group(action_group_id)]
+ #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(
+ ofp.instruction.goto_table(29)
+ ],
+ 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(ctrl, action_group_id=0x0, label=100 ,ethertype=0x0800, bos=1, vrf=1, send_barrier=False):
match = ofp.match()
match.oxm_list.append(ofp.oxm.eth_type(0x8847))
match.oxm_list.append(ofp.oxm.mpls_label(label))
@@ -787,8 +823,9 @@
actions = [ofp.action.dec_mpls_ttl(),
ofp.action.copy_ttl_in(),
ofp.action.set_field(ofp.oxm.exp2ByteValue(exp_type=1, value=vrf)),
- ofp.action.set_field(ofp.oxm.exp2ByteValue(exp_type=23, value=8)),
- ofp.action.pop_mpls(ethertype)]
+ ofp.action.set_field(ofp.oxm.exp2ByteValue(exp_type=23, value=32))]
+ #ofp.action.group(action_group_id)]
+ #ofp.action.pop_mpls(ethertype)]
request = ofp.message.flow_add(
table_id=24,
diff --git a/ofdpa/flows.py b/ofdpa/flows.py
index 9d39e91..1ec015d 100755
--- a/ofdpa/flows.py
+++ b/ofdpa/flows.py
@@ -1058,7 +1058,7 @@
delete_all_flows(self.controller)
delete_groups(self.controller, Groups)
-
+@disabled
class L3McastToL3(base_tests.SimpleDataPlane):
"""
Mcast routing
@@ -1147,7 +1147,7 @@
delete_groups(self.controller, Groups)
-class _MplsTermination(base_tests.SimpleDataPlane):
+class _MplsFwd(base_tests.SimpleDataPlane):
"""
Insert IP packet
Receive MPLS packet
@@ -1169,6 +1169,20 @@
l2_gid, l2_msg = add_one_l2_interface_group(self.controller, port,
vlan_id, True, False)
dst_mac[5] = vlan_id
+ mpls_gid, mpls_msg = add_mpls_intf_group(self.controller, l2_gid,
+ dst_mac, intf_src_mac,
+ vlan_id, id)
+ mpls_label_gid, mpls_label_msg = add_mpls_label_group(
+ self.controller,
+ subtype=OFDPA_MPLS_GROUP_SUBTYPE_SWAP_LABEL,
+ index=id, ref_gid=mpls_gid, push_mpls_header=False,
+ set_mpls_label=port, set_bos=1)
+ #, set_ttl=32)
+ mpls_ecmp_gid, mpls_ecmp_msg = add_mpls_forwarding_group(
+ self.controller,
+ subtype=OFDPA_MPLS_GROUP_SUBTYPE_ECMP,
+ index=id,
+ ref_gids=[mpls_label_gid])
# add L3 Unicast group
l3_msg = add_l3_unicast_group(self.controller, port, vlanid=vlan_id,
id=id, src_mac=intf_src_mac,
@@ -1181,11 +1195,13 @@
# add termination flow
add_termination_flow(self.controller, port, 0x8847, intf_src_mac,
vlan_id, goto_table=24)
- add_mpls_flow(self.controller, ecmp_msg.group_id, port)
+ #add_mpls_flow(self.controller, ecmp_msg.group_id, port)
+ add_mpls(self.controller, mpls_label_gid, port)
dst_ip = dip + (vlan_id << 8)
- add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0xffffff00,
- ecmp_msg.group_id, 1)
+ #add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0xffffff00,
+ # ecmp_msg.group_id, 1)
Groups._put(l2_gid)
+ Groups._put(mpls_gid)
Groups._put(l3_msg.group_id)
Groups._put(ecmp_msg.group_id)
do_barrier(self.controller)
@@ -1208,6 +1224,72 @@
# build expect packet
mac_dst = '00:00:00:22:22:%02X' % (out_port)
+ label = (out_port, 0, 1, 31)
+ exp_pkt = mpls_packet(pktlen=104, dl_vlan_enable=True,
+ vlan_vid=(out_port), ip_src=ip_src,
+ ip_dst=ip_dst, eth_src=switch_mac,
+ eth_dst=mac_dst,label=[label])
+ pkt = str(exp_pkt)
+ verify_packet(self, pkt, out_port)
+ verify_no_other_packets(self)
+ delete_all_flows(self.controller)
+ delete_groups(self.controller, Groups)
+
+class _MplsTermination(base_tests.SimpleDataPlane):
+ """
+ Insert IP packet
+ Receive MPLS packet
+ """
+ def runTest(self):
+ Groups = Queue.LifoQueue()
+ if len(config["port_map"]) < 2:
+ logging.info("Port count less than 2, can't run this case")
+ return
+ dip = 0xc0a80001
+ intf_src_mac = [0x00, 0x00, 0x00, 0xcc, 0xcc, 0xcc]
+ dst_mac = [0x00, 0x00, 0x00, 0x22, 0x22, 0x00]
+ # Assigns unique hardcoded test_id to make sure tests don't overlap when writing rules
+ ports = config["port_map"].keys()
+ for port in ports:
+ # add l2 interface group
+ vlan_id, id, dst_mac[5] = port, port, port
+ l2_gid, l2_msg = add_one_l2_interface_group(self.controller, port,
+ vlan_id, True, False)
+ # add L3 Unicast group
+ l3_msg = add_l3_unicast_group(self.controller, port, vlanid=vlan_id,
+ id=id, src_mac=intf_src_mac,dst_mac=dst_mac)
+ # add L3 ecmp group
+ ecmp_msg = add_l3_ecmp_group(self.controller, id, [l3_msg.group_id])
+ # add vlan flow table
+ add_one_vlan_table_flow(self.controller, port, vlan_id,
+ flag=VLAN_TABLE_FLAG_ONLY_TAG)
+ # add termination flow
+ add_termination_flow(self.controller, port, 0x8847, intf_src_mac,
+ vlan_id, goto_table=24)
+ #add_mpls_flow(self.controller, ecmp_msg.group_id, port)
+ add_mpls_flow(self.controller, label=port)
+ dst_ip = dip + (vlan_id << 8)
+ add_unicast_routing_flow(self.controller, 0x0800, dst_ip, 0xffffff00,
+ ecmp_msg.group_id, 1)
+ Groups._put(l2_gid)
+ Groups._put(l3_msg.group_id)
+ Groups._put(ecmp_msg.group_id)
+ do_barrier(self.controller)
+
+ switch_mac = ':'.join(['%02X' % x for x in intf_src_mac])
+ for in_port in ports:
+ 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)
+ label = (out_port, 0, 1, 32)
+ parsed_pkt = mpls_packet(pktlen=104, dl_vlan_enable=True,vlan_vid=(in_port),
+ ip_src=ip_src,ip_dst=ip_dst, eth_dst=switch_mac,label=[label])
+ pkt = str(parsed_pkt)
+ self.dataplane.send(in_port, pkt)
+ # build expect 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),
eth_dst=mac_dst, eth_src=switch_mac,