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