blob: 4942d44e374f75fb84420488ac260ee4f9f8e590 [file] [log] [blame]
Yi Tseng0cb9b562021-09-22 17:13:58 -07001# SPDX-FileCopyrightText: Copyright 2021-present Open Networking Foundation.
2# SPDX-License-Identifier: GPL-2.0-or-later
3
4class INT:
5
6 def __init__(self):
7 self.default = ""
8
9 def CASE1 (self, main):
Yi Tseng2521bd42021-10-01 15:07:06 -070010 main.case("Send ping packets from one host to another host and check flows from DeepInsight")
Yi Tseng0cb9b562021-09-22 17:13:58 -070011 import time
12 import socket
13 from core import utilities
14 from tests.USECASE.SegmentRouting.INT.dependencies.IntTest import IntTest
15 main.cfgName = "CASE1"
16
17 main.step("Setting up the test")
18 intTest = IntTest(scapy=True)
19 intTest.setUpTest(main)
20
21 main.step("Setting up hosts and variables")
22 srcIfaceName = main.h1.interfaces[0]["name"]
23 dstIfaceName = main.h2.interfaces[0]["name"]
24 srcMac = main.h1.getMac(srcIfaceName)
25 dstMac = main.h2.getMac(dstIfaceName)
26 srcIp = main.h1.getIp(srcIfaceName)
27 dstIp = main.h2.getIp(dstIfaceName)
28 srcPort = 2000
29 dstPort = 8888
30
31 main.step("Send ping packets from h1 to h2")
32 startTimeMs = (time.time() - 5) * 1000
33 pkt = """(
34 Ether(src="{}", dst="{}") /
35 IP(src="{}", dst="{}") /
36 UDP(sport={}, dport={}) /
37 ("A"*30)
38 )""".format(srcMac, dstMac, srcIp, dstIp, srcPort, dstPort)
Yi Tseng2521bd42021-10-01 15:07:06 -070039 # Send multiple packets incase the server or DeepInsight drop the report accidently
40 # FIXME: Find the root cause, might be misconfiguration or Linux(e.g., rp_filter?) issue.
41 for _ in range(0, 5):
42 main.h1.sendPacket(iface=srcIfaceName, packet=pkt)
Yi Tseng0cb9b562021-09-22 17:13:58 -070043 endTimeMs = (time.time() + 5) * 1000
44
45 main.step("Checking total number of flow reports from DeepInsight")
46 def getFiveTupleCount(*args, **kwargs):
47 flows = main.DeepInsight.getFlows(
48 startTimeMs=startTimeMs,
49 endTimeMs=endTimeMs,
50 srcIp=srcIp,
51 dstIp=dstIp,
52 ipProto=socket.IPPROTO_UDP
53 )
54 if "FiveTupleCount" in flows:
55 return flows["FiveTupleCount"]
56 else:
57 return 0
58 # Need to wait few seconds until DeepInsight database updated.
59 fiveTupleCount = utilities.retry(
60 f=getFiveTupleCount,
61 retValue=0,
62 attempts=60,
63 )
64
65 utilities.assert_equals(
66 expect=1, actual=fiveTupleCount,
67 onpass="Got 1 flow report from DeepInsight as expected.",
68 onfail="Got %d flow reports from DeepInsight (expect 1)" % (fiveTupleCount)
69 )
70
71 main.step("Clean up the test")
72 intTest.cleanUp(main)
73
74 def CASE2 (self, main):
Yi Tseng2521bd42021-10-01 15:07:06 -070075 main.case("Send a packet with invalid VLAN from one host to another host and check if DeepInsight receives drop reports")
Yi Tseng0cb9b562021-09-22 17:13:58 -070076 import time
77 import socket
78 from core import utilities
79 from tests.USECASE.SegmentRouting.INT.dependencies.IntTest import IntTest
80 main.cfgName = "CASE2"
81
82 main.step("Setting up the test")
83 intTest = IntTest(scapy=True)
84 intTest.setUpTest(main)
85
86 main.step("Setting up hosts and variables")
87 srcIfaceName = main.h1.interfaces[0]["name"]
88 dstIfaceName = main.h2.interfaces[0]["name"]
89 srcMac = main.h1.getMac(srcIfaceName)
90 dstMac = main.h2.getMac(dstIfaceName)
91 srcIp = main.h1.getIp(srcIfaceName)
92 dstIp = main.h2.getIp(dstIfaceName)
93 srcPort = 2000
94 dstPort = 8888
95
96 main.step("Sending a packet with invalid VLAN ID from h1")
97 startTimeMs = (time.time() - 5) * 1000
98 pkt = """(
99 Ether(src="{}", dst="{}") /
100 Dot1Q(vlan=4093) /
101 IP(src="{}", dst="{}") /
102 UDP(sport={}, dport={}) /
103 ("A"*30)
104 )""".format(srcMac, dstMac, srcIp, dstIp, srcPort, dstPort)
Yi Tseng2521bd42021-10-01 15:07:06 -0700105 # Send multiple packets incase the server or DeepInsight drop the report accidently
106 # FIXME: Find the root cause, might be misconfiguration or Linux(e.g., rp_filter?) issue.
107 for _ in range(0, 5):
108 main.h1.sendPacket(iface=srcIfaceName, packet=pkt)
Yi Tseng0cb9b562021-09-22 17:13:58 -0700109 endTimeMs = (time.time() + 5) * 1000
110
111 main.step("Checking drop report from DeepInsight")
112 def getDropAnomalies(*args, **kwargs):
113 return main.DeepInsight.getAnomalyRecords(
114 startTime=startTimeMs,
115 endTime=endTimeMs,
116 srcIp=srcIp,
117 dstIp=dstIp,
118 srcPort=srcPort,
119 dstPort=dstPort,
120 ipProto=socket.IPPROTO_UDP,
121 anomalyType="packet_drop",
122 )
123
124 # Need to wait few seconds until DeepInsight database updated.
125 dropAnomalies = utilities.retry(
126 f=getDropAnomalies,
127 retValue=[[]],
128 attempts=60,
129 )
130
Yi Tseng2521bd42021-10-01 15:07:06 -0700131 utilities.assert_lesser(
132 expect=0, actual=len(dropAnomalies),
133 onpass="Got %d drop anomaly from DeepInsight." % (len(dropAnomalies)),
134 onfail="Got no drop anomaly from DeepInsight."
Yi Tseng0cb9b562021-09-22 17:13:58 -0700135 )
136
137 main.step("Checking drop reason from the report")
138 dropAnomaly = dropAnomalies[0]
139 dropReason = dropAnomaly["DropReason"]
140
141 # DROP_REASON_PORT_VLAN_MAPPING_MISS = 55
142 utilities.assert_equals(
143 expect=55, actual=dropReason,
144 onpass="Got drop reason '55' as expected.",
145 onfail="Got drop reason '%d', expect '55'." % (dropReason)
146 )
147
148 main.step("Clean up the test")
149 intTest.cleanUp(main)
150
151 def CASE3 (self, main):
Yi Tseng2521bd42021-10-01 15:07:06 -0700152 main.case("Send a packet with IP TTL value 1 from one host to another host and check if DeepInsight receives drop reports")
Yi Tseng0cb9b562021-09-22 17:13:58 -0700153 import time
154 import socket
155 from core import utilities
156 from tests.USECASE.SegmentRouting.INT.dependencies.IntTest import IntTest
157 main.cfgName = "CASE3"
158
159 main.step("Setting up the test")
160 intTest = IntTest(scapy=True)
161 intTest.setUpTest(main)
162
163 main.step("Setting up hosts and variables")
164 srcIfaceName = main.h1.interfaces[0]["name"]
165 dstIfaceName = main.h3.interfaces[0]["name"]
166 srcMac = main.h1.getMac(srcIfaceName)
167 dstMac = main.params.get("routerMac", "00:00:00:00:00:00")
168 srcIp = main.h1.getIp(srcIfaceName)
169 dstIp = main.h3.getIp(dstIfaceName)
170 srcPort = 3000
171 dstPort = 8888
172
173 main.step("Sending a packet with IP TTL value 1 from h1")
174 startTimeMs = (time.time() - 5) * 1000
175 pkt = """(
176 Ether(src="{}", dst="{}") /
177 IP(src="{}", dst="{}", ttl=1) /
178 UDP(sport={}, dport={}) /
179 ("A"*30)
180 )""".format(srcMac, dstMac, srcIp, dstIp, srcPort, dstPort)
Yi Tseng2521bd42021-10-01 15:07:06 -0700181 # Send multiple packets incase the server or DeepInsight drop the report accidently
182 # FIXME: Find the root cause, might be misconfiguration or Linux(e.g., rp_filter?) issue.
183 for _ in range(0, 5):
184 main.h1.sendPacket(iface=srcIfaceName, packet=pkt)
Yi Tseng0cb9b562021-09-22 17:13:58 -0700185 endTimeMs = (time.time() + 5) * 1000
186
187 main.step("Checking drop report from DeepInsight")
188 def getDropAnomalies(*args, **kwargs):
189 return main.DeepInsight.getAnomalyRecords(
190 startTime=startTimeMs,
191 endTime=endTimeMs,
192 srcIp=srcIp,
193 dstIp=dstIp,
194 srcPort=srcPort,
195 dstPort=dstPort,
196 ipProto=socket.IPPROTO_UDP,
197 anomalyType="packet_drop",
198 )
199
200 # Need to wait few seconds until DeepInsight database updated.
201 dropAnomalies = utilities.retry(
202 f=getDropAnomalies,
203 retValue=[[]],
204 attempts=60,
205 )
206
Yi Tseng2521bd42021-10-01 15:07:06 -0700207 utilities.assert_lesser(
208 expect=0, actual=len(dropAnomalies),
209 onpass="Got %d drop anomaly from DeepInsight." % (len(dropAnomalies)),
210 onfail="Got no drop anomaly from DeepInsight."
Yi Tseng0cb9b562021-09-22 17:13:58 -0700211 )
212
213 main.step("Checking drop reason from report")
214 dropAnomaly = dropAnomalies[0]
215 dropReason = dropAnomaly["DropReason"]
216 # DROP_REASON_IP_TTL_ZERO = 26
217 utilities.assert_equals(
218 expect=26, actual=dropReason,
219 onpass="Got drop reason '26' as expected.",
220 onfail="Got drop reason '%d', expect '26'." % (dropReason)
221 )
222
223 main.step("Clean up the test")
224 intTest.cleanUp(main)
Yi Tsengdda7e322021-09-20 14:21:20 -0700225
226 def CASE4(self, main):
Yi Tseng2521bd42021-10-01 15:07:06 -0700227 main.case("Generate traffic at high rate and expect queue congestion reports in DeepInsight")
Yi Tsengdda7e322021-09-20 14:21:20 -0700228 from core import utilities
229 import time
230 from tests.USECASE.SegmentRouting.INT.dependencies.IntTest import IntTest
231 from tests.USECASE.SegmentRouting.dependencies.trex import Trex
232 main.cfgName = 'CASE4'
233
234 main.step("Setting up the test")
235 intTest = IntTest(scapy=False)
236 intTest.setUpTest(main)
237 dstIp = main.params["TREX"]["flows"]["FLOW1"]["packet"]["ip_dst"]
238
239 main.step("Set up TRex client")
240 trex = Trex()
241 trex.setup(main.TRexClient)
242
243 # See SRpairedLeaves.param for the detail of each flow.
244 main.step("Reset queue report filter")
245 # Here we are using a low-latency(no congestion) traffic to reset the queue.
246 # report filter.
247 trex.createFlow("RESET_QUEUE_REPORT_FILTER")
248 trex.sendAndReceiveTraffic(5)
249 trex.resetFlows()
250 main.step("Generating traffic")
251 startTimeMs = (time.time() - 5) * 1000
252 trex.createFlow("FLOW1")
253 trex.createFlow("FLOW2")
254 trex.sendAndReceiveTraffic(10)
255 endTimeMs = (time.time() + 5) * 1000
256
257 main.step("Checking queue report from DeepInsight")
258 def getQueueAnomaly(*args, **kwargs):
259 return main.DeepInsight.getAnomalyRecords(
260 startTime=startTimeMs,
261 endTime=endTimeMs,
262 dstIp=dstIp,
263 anomalyType="congested_flow",
264 )
265
266 # Need to wait few seconds until DeepInsight database updated.
267 queueAnomalies = utilities.retry(
268 f=getQueueAnomaly,
269 retValue=[[]],
Yi Tseng2521bd42021-10-01 15:07:06 -0700270 attempts=120,
Yi Tsengdda7e322021-09-20 14:21:20 -0700271 )
272
273 # We should get at least two congestion records
274 utilities.assert_lesser(
275 expect=2, actual=len(queueAnomalies),
276 onpass="Got %d anomalies with 'congested_flow' type as expcted." % (len(queueAnomalies)),
277 onfail="Did not get any anomaly with 'congested_flow' type."
278 )
279
280 main.step("Clean up the test")
281 trex.teardown()
282 intTest.cleanUp(main)