Skip to content
This repository was archived by the owner on Mar 21, 2025. It is now read-only.

Commit 2cc9aea

Browse files
authored
Merge pull request #59 from eggqq007/master
third-party plugin inject flows
2 parents d863e15 + 32fb4d2 commit 2cc9aea

File tree

7 files changed

+56
-12
lines changed

7 files changed

+56
-12
lines changed

src/tests/test_smoke_lr.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ port_add hv1 lsp-portA || exit_test
2525
port_add hv2 lsp-portB || exit_test
2626

2727
prev_LS=LS-A
28-
max_lr_num=20 # we cannot make it 50 or bigger, because the ovs may treat the packet as a recircle packet
28+
max_lr_num=15 # we cannot make it 50 or bigger, because the ovs may treat the packet as a recircle packet
2929
last_subnet_id=$((max_lr_num+1))
3030
i=1
3131
while [ $i -le $max_lr_num ]; do
@@ -63,8 +63,8 @@ packet=`build_icmp_request 000006080703 000006080601 $ip_src $ip_dst $ttl 528d 8
6363
inject_pkt hv1 lsp-portA "$packet" || exit_test
6464
wait_for_packet # wait for packet
6565

66-
ttl=ea
67-
expect_pkt=`build_icmp_request 0000060805${mac_hex} 000006080704 $ip_src $ip_dst $ttl 668d 8510`
66+
ttl=ef
67+
expect_pkt=`build_icmp_request 0000060805${mac_hex} 000006080704 $ip_src $ip_dst $ttl 618d 8510`
6868
real_pkt=`get_tx_pkt hv2 lsp-portB`
6969
verify_pkt $expect_pkt $real_pkt || exit_test
7070

@@ -74,8 +74,8 @@ ttl=fe
7474
packet=`build_icmp_request 000006080703 000006080601 $ip_src $ip_dst $ttl 528f 8510`
7575
inject_pkt hv1 lsp-portA "$packet" || exit_test
7676
wait_for_packet # wait for packet
77-
ttl=eb
78-
expect_pkt=`build_icmp_response 000006080601 000006080703 $ip_dst $ip_src $ttl 658f 8d10`
77+
ttl=f0
78+
expect_pkt=`build_icmp_response 000006080601 000006080703 $ip_dst $ip_src $ttl 608f 8d10`
7979
real_pkt=`get_tx_pkt hv1 lsp-portA`
8080
verify_pkt $expect_pkt $real_pkt || exit_test
8181

src/tuplenet/lcp/action.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@
9898
Action_mod_nw_dst:'mod_nw_dst:{}',
9999
Action_mod_nw_ttl:'mod_nw_ttl:{}',
100100
Action_dec_ttl:'dec_ttl',
101+
Action_mod_tp_dst:'mod_tp_dst:{}',
102+
Action_mod_tp_src:'mod_tp_src:{}',
101103

102104
Action_resubmit:'resubmit({},{})',
103105
Action_resubmit_table:'resubmit(,{})',

src/tuplenet/lcp/flow_common.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
TABLE_CONVERT_PHY_LOGICAL = 0
33
# LSP pipeline
44
TABLE_LSP_TRACE_INGRESS_IN = 1
5-
TABLE_LSP_INGRESS_ARP_CONTROLLER = 2
6-
TABLE_LSP_INGRESS_ARP_RESPONSE = 3
7-
TABLE_LSP_INGRESS_UNTUNNEL = 4
8-
TABLE_LSP_INGRESS_LOOKUP_DST_PORT = 5
9-
TABLE_LSP_INGRESS_OUTPUT_DST_PORT = 6
10-
TABLE_LSP_TRACE_INGRESS_OUT = 6 # same to TABLE_LSP_INGRESS_OUTPUT_DST_PORT
5+
TABLE_LSP_INGRESS_PROCESS_EXT_LOGIC = 2
6+
TABLE_LSP_INGRESS_ARP_CONTROLLER = 3
7+
TABLE_LSP_INGRESS_ARP_RESPONSE = 4
8+
TABLE_LSP_INGRESS_UNTUNNEL = 5
9+
TABLE_LSP_INGRESS_LOOKUP_DST_PORT = 6
10+
TABLE_LSP_INGRESS_OUTPUT_DST_PORT = 7
11+
TABLE_LSP_TRACE_INGRESS_OUT = 7 # same to TABLE_LSP_INGRESS_OUTPUT_DST_PORT
1112

1213
TABLE_LSP_TRACE_EGRESS_IN = 20
1314
TABLE_LSP_EGRESS_JUDGE_LOOPBACK = 21
@@ -53,6 +54,9 @@
5354
TABLE_SEARCH_IP_MAC = 100
5455
TABLE_DROP_PACKET = 101
5556

57+
# third-party table
58+
TABLE_THIRD_PARTY = 201
59+
5660
flows_note_array = ['lsp_lookup_dst_port',
5761
'lsp_output_dst_port',
5862
'lsp_pushout_packet',
@@ -95,6 +99,7 @@
9599
'pipeline_forward',
96100
'redirect_other_chassis',
97101
'output_pkt',
102+
'process_third_logic',
98103
]
99104

100105
START_IDX = 10
@@ -112,6 +117,7 @@ def flows_idx2note(idx):
112117
table_note_dict = {
113118
TABLE_CONVERT_PHY_LOGICAL:'TABLE_CONVERT_PHY_LOGICAL',
114119
TABLE_LSP_TRACE_INGRESS_IN:'TABLE_LSP_TRACE_INGRESS_IN',
120+
TABLE_LSP_INGRESS_PROCESS_EXT_LOGIC:'TABLE_LSP_INGRESS_PROCESS_EXT_LOGIC',
115121
TABLE_LSP_INGRESS_ARP_RESPONSE:'TABLE_LSP_INGRESS_ARP_RESPONSE',
116122
TABLE_LSP_INGRESS_ARP_CONTROLLER:'TABLE_LSP_INGRESS_ARP_CONTROLLER',
117123
TABLE_LSP_INGRESS_UNTUNNEL:'TABLE_LSP_INGRESS_UNTUNNEL',
@@ -143,4 +149,5 @@ def flows_idx2note(idx):
143149
TABLE_OUTPUT_PKT:'TABLE_OUTPUT_PKT',
144150
TABLE_SEARCH_IP_MAC:'TABLE_SEARCH_IP_MAC',
145151
TABLE_DROP_PACKET:'TABLE_DROP_PACKET',
152+
TABLE_THIRD_PARTY:'TABLE_THIRD_PARTY',
146153
}

src/tuplenet/lcp/lflow.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ def init_build_flows_clause(options):
220220
(Match == Match1 + Match2)
221221
)
222222

223-
# build const trace flow for in first stage of lsp ingress
223+
# build const trace flow in first stage of lsp ingress
224224
build_flows_lsp(Table, Priority, Match, Action) <= (
225225
(Table == TABLE_LSP_TRACE_INGRESS_IN) &
226226
action.load(0, NXM_Reg(REG_DST_IDX), Action1) &
@@ -253,6 +253,27 @@ def init_build_flows_clause(options):
253253
(Action == Action1 + Action2)
254254
)
255255

256+
# build const flows to forward packet to third party table
257+
build_flows_lsp(Table, Priority, Match, Action) <= (
258+
(Table == TABLE_LSP_INGRESS_PROCESS_EXT_LOGIC) &
259+
(Priority == 0) &
260+
match.match_none(Match) &
261+
action.resubmit_table(TABLE_THIRD_PARTY, Action1) &
262+
action.note(flows_note2idx('process_third_logic'), Action2) &
263+
(Action == Action1 + Action2)
264+
)
265+
266+
build_flows_lsp(Table, Priority, Match, Action) <= (
267+
(Table == TABLE_THIRD_PARTY) &
268+
(Priority == 0) &
269+
match.match_none(Match) &
270+
action.resubmit_table(TABLE_LSP_INGRESS_PROCESS_EXT_LOGIC+1, Action1) &
271+
action.note(flows_note2idx('process_third_logic'), Action2) &
272+
(Action == Action1 + Action2)
273+
)
274+
275+
# build trace flow in end stage of lsp egress
276+
# build trace flow in end stage of lsp egress
256277
# build trace flow in end stage of lsp egress
257278
# because the end stage of lsp egress has no uniq path, so
258279
# we have to add similar flows(simliar to regular flow) to trace
@@ -452,6 +473,7 @@ def init_build_flows_clause(options):
452473
(Action == Action1 + Action2 + Action3)
453474
)
454475

476+
455477
#---------------------const drop table--------------------------------
456478
build_flows_drop(Table, Priority, Match, Action) <= (
457479
(Priority == 0) &
@@ -469,3 +491,4 @@ def init_build_flows_clause(options):
469491
action.note(flows_note2idx('pkt_trace_drop_packet'), Action2) &
470492
(Action == Action1 + Action2)
471493
)
494+

src/tuplenet/lcp/lsp_ingress.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
pyDatalog.create_terms('lsp_lookup_dst_port')
1313
pyDatalog.create_terms('lsp_arp_controller')
1414
pyDatalog.create_terms('lsp_arp_response')
15+
pyDatalog.create_terms('lsp_process_third_logic')
1516
pyDatalog.create_terms('lsp_untunnel_deliver')
1617
pyDatalog.create_terms('_lsp_remote_lsp_changed, _lsp_lrp_ls_changed')
1718

src/tuplenet/lcp/match.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
pyDatalog.create_terms('arp_proto')
2929
pyDatalog.create_terms('arp_tpa')
3030
pyDatalog.create_terms('arp_op')
31+
pyDatalog.create_terms('tcp_proto')
32+
pyDatalog.create_terms('tcp_dstport')
33+
pyDatalog.create_terms('tcp_srcport')
3134

3235
pyDatalog.create_terms('icmp_proto, icmp_type, icmp_code')
3336

@@ -90,6 +93,12 @@ def init_match_clause():
9093

9194
icmp_code(X, Y) <= (Y == [(ICMP_CODE_IDX, X)])
9295

96+
tcp_proto(X) <= (X == [(TCP_PROTO_IDX, )])
97+
98+
tcp_dstport(X, Y) <= (Y == [(TCP_DST_IDX, X)])
99+
100+
tcp_srcport(X, Y) <= (Y == [(TCP_SRC_IDX, X)])
101+
93102
def convert_flags(flags):
94103
# e.g flag = 1 means it occupies the first bit
95104
# and flag = 4 means it occupies the third bit

src/tuplenet/tp_utils/pipe.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ def read_debug_pipe(param):
4848
logger.exception("hit error in debug pipe, err:%s", err)
4949

5050
try:
51+
if os.path.exists(DEBUG_PIPE_PATH):
52+
os.remove(DEBUG_PIPE_PATH)
5153
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
5254
sock.bind(addr)
5355
except Exception as err:

0 commit comments

Comments
 (0)