blob: d307c9d555e09d49980c1a34530b80d9e4df02a8 [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)
Yi Tseng69cdb172022-02-23 10:52:10 -080026 srcIp = main.h1.interfaces[0]['ips'][0]
27 dstIp = main.h2.interfaces[0]['ips'][0]
Yi Tseng0cb9b562021-09-22 17:13:58 -070028 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)
Yi Tseng69cdb172022-02-23 10:52:10 -080091 srcIp = main.h1.interfaces[0]['ips'][0]
92 dstIp = main.h2.interfaces[0]['ips'][0]
Yi Tseng0cb9b562021-09-22 17:13:58 -070093 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"]
Yi Tseng0cb9b562021-09-22 17:13:58 -0700170 srcMac = main.h1.getMac(srcIfaceName)
171 dstMac = main.params.get("routerMac", "00:00:00:00:00:00")
Yi Tseng69cdb172022-02-23 10:52:10 -0800172 srcIp = main.h1.interfaces[0]['ips'][0]
173 dstIp = main.h2.interfaces[0]['ips'][0]
Yi Tseng0cb9b562021-09-22 17:13:58 -0700174 srcPort = 3000
175 dstPort = 8888
176
177 main.step("Sending a packet with IP TTL value 1 from h1")
178 startTimeMs = (time.time() - 5) * 1000
179 pkt = """(
180 Ether(src="{}", dst="{}") /
181 IP(src="{}", dst="{}", ttl=1) /
182 UDP(sport={}, dport={}) /
183 ("A"*30)
184 )""".format(srcMac, dstMac, srcIp, dstIp, srcPort, dstPort)
Yi Tseng2521bd42021-10-01 15:07:06 -0700185 # Send multiple packets incase the server or DeepInsight drop the report accidently
186 # FIXME: Find the root cause, might be misconfiguration or Linux(e.g., rp_filter?) issue.
187 for _ in range(0, 5):
188 main.h1.sendPacket(iface=srcIfaceName, packet=pkt)
Yi Tseng0cb9b562021-09-22 17:13:58 -0700189 endTimeMs = (time.time() + 5) * 1000
190
191 main.step("Checking drop report from DeepInsight")
192 def getDropAnomalies(*args, **kwargs):
193 return main.DeepInsight.getAnomalyRecords(
194 startTime=startTimeMs,
195 endTime=endTimeMs,
196 srcIp=srcIp,
197 dstIp=dstIp,
198 srcPort=srcPort,
199 dstPort=dstPort,
200 ipProto=socket.IPPROTO_UDP,
201 anomalyType="packet_drop",
202 )
203
204 # Need to wait few seconds until DeepInsight database updated.
205 dropAnomalies = utilities.retry(
206 f=getDropAnomalies,
207 retValue=[[]],
208 attempts=60,
209 )
210
Yi Tseng2521bd42021-10-01 15:07:06 -0700211 utilities.assert_lesser(
212 expect=0, actual=len(dropAnomalies),
213 onpass="Got %d drop anomaly from DeepInsight." % (len(dropAnomalies)),
214 onfail="Got no drop anomaly from DeepInsight."
Yi Tseng0cb9b562021-09-22 17:13:58 -0700215 )
216
217 main.step("Checking drop reason from report")
Jon Hall1567b362021-12-10 10:23:10 -0800218 try:
219 dropAnomaly = dropAnomalies[0]
220 dropReason = dropAnomaly["DropReason"]
221 except IndexError:
222 main.log.warn( "No drop report was found" )
223 dropAnomaly = None
224 dropReason = None
Yi Tseng0cb9b562021-09-22 17:13:58 -0700225 # DROP_REASON_IP_TTL_ZERO = 26
226 utilities.assert_equals(
227 expect=26, actual=dropReason,
228 onpass="Got drop reason '26' as expected.",
229 onfail="Got drop reason '%d', expect '26'." % (dropReason)
230 )
231
232 main.step("Clean up the test")
233 intTest.cleanUp(main)
Yi Tsengdda7e322021-09-20 14:21:20 -0700234
235 def CASE4(self, main):
Yi Tseng2521bd42021-10-01 15:07:06 -0700236 main.case("Generate traffic at high rate and expect queue congestion reports in DeepInsight")
Yi Tsengdda7e322021-09-20 14:21:20 -0700237 from core import utilities
238 import time
239 from tests.USECASE.SegmentRouting.INT.dependencies.IntTest import IntTest
240 from tests.USECASE.SegmentRouting.dependencies.trex import Trex
241 main.cfgName = 'CASE4'
242
243 main.step("Setting up the test")
244 intTest = IntTest(scapy=False)
245 intTest.setUpTest(main)
246 dstIp = main.params["TREX"]["flows"]["FLOW1"]["packet"]["ip_dst"]
247
248 main.step("Set up TRex client")
249 trex = Trex()
250 trex.setup(main.TRexClient)
251
252 # See SRpairedLeaves.param for the detail of each flow.
253 main.step("Reset queue report filter")
254 # Here we are using a low-latency(no congestion) traffic to reset the queue.
255 # report filter.
256 trex.createFlow("RESET_QUEUE_REPORT_FILTER")
257 trex.sendAndReceiveTraffic(5)
258 trex.resetFlows()
259 main.step("Generating traffic")
260 startTimeMs = (time.time() - 5) * 1000
261 trex.createFlow("FLOW1")
262 trex.createFlow("FLOW2")
263 trex.sendAndReceiveTraffic(10)
264 endTimeMs = (time.time() + 5) * 1000
265
266 main.step("Checking queue report from DeepInsight")
267 def getQueueAnomaly(*args, **kwargs):
268 return main.DeepInsight.getAnomalyRecords(
269 startTime=startTimeMs,
270 endTime=endTimeMs,
271 dstIp=dstIp,
272 anomalyType="congested_flow",
273 )
274
275 # Need to wait few seconds until DeepInsight database updated.
276 queueAnomalies = utilities.retry(
277 f=getQueueAnomaly,
278 retValue=[[]],
Yi Tseng69cdb172022-02-23 10:52:10 -0800279 attempts=30,
Yi Tsengdda7e322021-09-20 14:21:20 -0700280 )
281
282 # We should get at least two congestion records
283 utilities.assert_lesser(
284 expect=2, actual=len(queueAnomalies),
285 onpass="Got %d anomalies with 'congested_flow' type as expcted." % (len(queueAnomalies)),
286 onfail="Did not get any anomaly with 'congested_flow' type."
287 )
288
289 main.step("Clean up the test")
290 trex.teardown()
291 intTest.cleanUp(main)