blob: 3da88d42f2683df00cf8df617e0601a5c8b5ee56 [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")
Jon Hall1567b362021-12-10 10:23:10 -0800138 try:
139 dropAnomaly = dropAnomalies[0]
140 dropReason = dropAnomaly["DropReason"]
141 except IndexError:
142 main.log.warn( "No drop report was found" )
143 dropAnomaly = None
144 dropReason = None
Yi Tseng0cb9b562021-09-22 17:13:58 -0700145
146 # DROP_REASON_PORT_VLAN_MAPPING_MISS = 55
147 utilities.assert_equals(
148 expect=55, actual=dropReason,
149 onpass="Got drop reason '55' as expected.",
150 onfail="Got drop reason '%d', expect '55'." % (dropReason)
151 )
152
153 main.step("Clean up the test")
154 intTest.cleanUp(main)
155
156 def CASE3 (self, main):
Yi Tseng2521bd42021-10-01 15:07:06 -0700157 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 -0700158 import time
159 import socket
160 from core import utilities
161 from tests.USECASE.SegmentRouting.INT.dependencies.IntTest import IntTest
162 main.cfgName = "CASE3"
163
164 main.step("Setting up the test")
165 intTest = IntTest(scapy=True)
166 intTest.setUpTest(main)
167
168 main.step("Setting up hosts and variables")
169 srcIfaceName = main.h1.interfaces[0]["name"]
170 dstIfaceName = main.h3.interfaces[0]["name"]
171 srcMac = main.h1.getMac(srcIfaceName)
172 dstMac = main.params.get("routerMac", "00:00:00:00:00:00")
173 srcIp = main.h1.getIp(srcIfaceName)
174 dstIp = main.h3.getIp(dstIfaceName)
175 srcPort = 3000
176 dstPort = 8888
177
178 main.step("Sending a packet with IP TTL value 1 from h1")
179 startTimeMs = (time.time() - 5) * 1000
180 pkt = """(
181 Ether(src="{}", dst="{}") /
182 IP(src="{}", dst="{}", ttl=1) /
183 UDP(sport={}, dport={}) /
184 ("A"*30)
185 )""".format(srcMac, dstMac, srcIp, dstIp, srcPort, dstPort)
Yi Tseng2521bd42021-10-01 15:07:06 -0700186 # Send multiple packets incase the server or DeepInsight drop the report accidently
187 # FIXME: Find the root cause, might be misconfiguration or Linux(e.g., rp_filter?) issue.
188 for _ in range(0, 5):
189 main.h1.sendPacket(iface=srcIfaceName, packet=pkt)
Yi Tseng0cb9b562021-09-22 17:13:58 -0700190 endTimeMs = (time.time() + 5) * 1000
191
192 main.step("Checking drop report from DeepInsight")
193 def getDropAnomalies(*args, **kwargs):
194 return main.DeepInsight.getAnomalyRecords(
195 startTime=startTimeMs,
196 endTime=endTimeMs,
197 srcIp=srcIp,
198 dstIp=dstIp,
199 srcPort=srcPort,
200 dstPort=dstPort,
201 ipProto=socket.IPPROTO_UDP,
202 anomalyType="packet_drop",
203 )
204
205 # Need to wait few seconds until DeepInsight database updated.
206 dropAnomalies = utilities.retry(
207 f=getDropAnomalies,
208 retValue=[[]],
209 attempts=60,
210 )
211
Yi Tseng2521bd42021-10-01 15:07:06 -0700212 utilities.assert_lesser(
213 expect=0, actual=len(dropAnomalies),
214 onpass="Got %d drop anomaly from DeepInsight." % (len(dropAnomalies)),
215 onfail="Got no drop anomaly from DeepInsight."
Yi Tseng0cb9b562021-09-22 17:13:58 -0700216 )
217
218 main.step("Checking drop reason from report")
Jon Hall1567b362021-12-10 10:23:10 -0800219 try:
220 dropAnomaly = dropAnomalies[0]
221 dropReason = dropAnomaly["DropReason"]
222 except IndexError:
223 main.log.warn( "No drop report was found" )
224 dropAnomaly = None
225 dropReason = None
Yi Tseng0cb9b562021-09-22 17:13:58 -0700226 # DROP_REASON_IP_TTL_ZERO = 26
227 utilities.assert_equals(
228 expect=26, actual=dropReason,
229 onpass="Got drop reason '26' as expected.",
230 onfail="Got drop reason '%d', expect '26'." % (dropReason)
231 )
232
233 main.step("Clean up the test")
234 intTest.cleanUp(main)
Yi Tsengdda7e322021-09-20 14:21:20 -0700235
236 def CASE4(self, main):
Yi Tseng2521bd42021-10-01 15:07:06 -0700237 main.case("Generate traffic at high rate and expect queue congestion reports in DeepInsight")
Yi Tsengdda7e322021-09-20 14:21:20 -0700238 from core import utilities
239 import time
240 from tests.USECASE.SegmentRouting.INT.dependencies.IntTest import IntTest
241 from tests.USECASE.SegmentRouting.dependencies.trex import Trex
242 main.cfgName = 'CASE4'
243
244 main.step("Setting up the test")
245 intTest = IntTest(scapy=False)
246 intTest.setUpTest(main)
247 dstIp = main.params["TREX"]["flows"]["FLOW1"]["packet"]["ip_dst"]
248
249 main.step("Set up TRex client")
250 trex = Trex()
251 trex.setup(main.TRexClient)
252
253 # See SRpairedLeaves.param for the detail of each flow.
254 main.step("Reset queue report filter")
255 # Here we are using a low-latency(no congestion) traffic to reset the queue.
256 # report filter.
257 trex.createFlow("RESET_QUEUE_REPORT_FILTER")
258 trex.sendAndReceiveTraffic(5)
259 trex.resetFlows()
260 main.step("Generating traffic")
261 startTimeMs = (time.time() - 5) * 1000
262 trex.createFlow("FLOW1")
263 trex.createFlow("FLOW2")
264 trex.sendAndReceiveTraffic(10)
265 endTimeMs = (time.time() + 5) * 1000
266
267 main.step("Checking queue report from DeepInsight")
268 def getQueueAnomaly(*args, **kwargs):
269 return main.DeepInsight.getAnomalyRecords(
270 startTime=startTimeMs,
271 endTime=endTimeMs,
272 dstIp=dstIp,
273 anomalyType="congested_flow",
274 )
275
276 # Need to wait few seconds until DeepInsight database updated.
277 queueAnomalies = utilities.retry(
278 f=getQueueAnomaly,
279 retValue=[[]],
Yi Tseng2521bd42021-10-01 15:07:06 -0700280 attempts=120,
Yi Tsengdda7e322021-09-20 14:21:20 -0700281 )
282
283 # We should get at least two congestion records
284 utilities.assert_lesser(
285 expect=2, actual=len(queueAnomalies),
286 onpass="Got %d anomalies with 'congested_flow' type as expcted." % (len(queueAnomalies)),
287 onfail="Did not get any anomaly with 'congested_flow' type."
288 )
289
290 main.step("Clean up the test")
291 trex.teardown()
292 intTest.cleanUp(main)