2 * Copyright © 2016, 2017 Red Hat, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.netvirt.aclservice.tests;
10 import static org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.CONFIGURATION;
11 import static org.opendaylight.netvirt.aclservice.tests.StateInterfaceBuilderHelper.putNewStateInterface;
13 import java.util.Arrays;
14 import java.util.Collections;
15 import java.util.List;
16 import java.util.stream.Collectors;
17 import javax.inject.Inject;
18 import org.junit.Before;
19 import org.junit.Ignore;
20 import org.junit.Rule;
21 import org.junit.Test;
22 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
23 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
24 import org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker;
25 import org.opendaylight.genius.datastoreutils.testutils.AsyncEventsWaiter;
26 import org.opendaylight.genius.datastoreutils.testutils.JobCoordinatorEventsWaiter;
27 import org.opendaylight.genius.mdsalutil.FlowEntity;
28 import org.opendaylight.genius.mdsalutil.NwConstants;
29 import org.opendaylight.genius.mdsalutil.interfaces.testutils.TestIMdsalApiManager;
30 import org.opendaylight.infrautils.testutils.LogRule;
31 import org.opendaylight.netvirt.aclservice.tests.infra.DataBrokerPairsUtil;
32 import org.opendaylight.netvirt.aclservice.utils.AclConstants;
33 import org.opendaylight.netvirt.aclservice.utils.AclServiceTestUtils;
34 import org.opendaylight.netvirt.aclservice.utils.AclServiceUtils;
35 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.Matches;
36 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.MatchesBuilder;
37 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.matches.ace.type.AceIpBuilder;
38 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.matches.ace.type.ace.ip.ace.ip.version.AceIpv4Builder;
39 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix;
40 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
41 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber;
42 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.packet.fields.rev160218.acl.transport.header.fields.DestinationPortRangeBuilder;
43 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
44 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.DirectionEgress;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.DirectionIngress;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.IpPrefixOrAddress;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.interfaces._interface.AllowedAddressPairs;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.interfaces._interface.AllowedAddressPairsBuilder;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.instances.ElanInstance;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.instances.ElanInstanceBuilder;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.interfaces.ElanInterface;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.interfaces.ElanInterfaceBuilder;
54 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
55 import org.slf4j.Logger;
56 import org.slf4j.LoggerFactory;
58 public abstract class AclServiceTestBase {
59 private static final Logger LOG = LoggerFactory.getLogger(AclServiceTestBase.class);
61 public @Rule LogRule logRule = new LogRule();
63 // public static @ClassRule RunUntilFailureClassRule classRepeater = new RunUntilFailureClassRule();
64 // public @Rule RunUntilFailureRule repeater = new RunUntilFailureRule(classRepeater);
66 static final String PORT_MAC_1 = "0D:AA:D8:42:30:F3";
67 static final String PORT_MAC_2 = "0D:AA:D8:42:30:F4";
68 static final String PORT_MAC_3 = "0D:AA:D8:42:30:F5";
69 static final String PORT_MAC_4 = "0D:AA:D8:42:30:F6";
70 static final String PORT_1 = "port1";
71 static final String PORT_2 = "port2";
72 static final String PORT_3 = "port3";
73 static final String PORT_4 = "port4";
74 static String SG_UUID = "85cc3048-abc3-43cc-89b3-377341426ac5";
75 static String SR_UUID_1 = "85cc3048-abc3-43cc-89b3-377341426ac6";
76 static String SR_UUID_2 = "85cc3048-abc3-43cc-89b3-377341426ac7";
77 static String SG_UUID_1 = "85cc3048-abc3-43cc-89b3-377341426ac5";
78 static String SG_UUID_2 = "85cc3048-abc3-43cc-89b3-377341426ac8";
79 static String SR_UUID_1_1 = "85cc3048-abc3-43cc-89b3-377341426ac6";
80 static String SR_UUID_1_2 = "85cc3048-abc3-43cc-89b3-377341426ac7";
81 static String SR_UUID_2_1 = "85cc3048-abc3-43cc-89b3-377341426a21";
82 static String SR_UUID_2_2 = "85cc3048-abc3-43cc-89b3-377341426a22";
83 static String ELAN = "elan1";
84 static String IP_PREFIX_1 = "10.0.0.1/32";
85 static String IP_PREFIX_2 = "10.0.0.2/32";
86 static String IP_PREFIX_3 = "10.0.0.3/32";
87 static String IP_PREFIX_4 = "10.0.0.4/32";
88 static long ELAN_TAG = 5000L;
90 static final AllowedAddressPairs AAP_PORT_1 = buildAap(IP_PREFIX_1, PORT_MAC_1);
91 static final AllowedAddressPairs AAP_PORT_2 = buildAap(IP_PREFIX_2, PORT_MAC_2);
92 static final AllowedAddressPairs AAP_PORT_3 = buildAap(IP_PREFIX_3, PORT_MAC_3);
93 static final AllowedAddressPairs AAP_PORT_4 = buildAap(IP_PREFIX_4, PORT_MAC_4);
95 @Inject DataBroker dataBroker;
96 @Inject DataBrokerPairsUtil dataBrokerUtil;
97 SingleTransactionDataBroker singleTransactionDataBroker;
98 @Inject TestIMdsalApiManager mdsalApiManager;
99 @Inject AsyncEventsWaiter asyncEventsWaiter;
100 @Inject JobCoordinatorEventsWaiter coordinatorEventsWaiter;
103 public void beforeEachTest() throws Exception {
104 singleTransactionDataBroker = new SingleTransactionDataBroker(dataBroker);
109 public void newInterface() throws Exception {
110 LOG.info("newInterface - start");
112 newAllowedAddressPair(PORT_1, Collections.singletonList(SG_UUID_1), Collections.singletonList(AAP_PORT_1));
114 // putNewInterface(dataBroker, "port1", true, Collections.emptyList(), Collections.emptyList());
116 ImmutableIdentifiedInterfaceWithAclBuilder.builder().interfaceName("port1").portSecurity(true).build());
119 putNewStateInterface(dataBroker, "port1", PORT_MAC_1);
121 AclServiceTestUtils.waitABit(asyncEventsWaiter);
125 LOG.info("newInterface - end");
128 abstract void newInterfaceCheck();
131 public void newInterfaceWithEtherTypeAcl() throws Exception {
132 LOG.info("newInterfaceWithEtherTypeAcl - start");
134 newAllowedAddressPair(PORT_1, Collections.singletonList(SG_UUID_1), Collections.singletonList(AAP_PORT_1));
135 newAllowedAddressPair(PORT_2, Collections.singletonList(SG_UUID_1), Collections.singletonList(AAP_PORT_2));
137 Matches matches = newMatch(AclConstants.SOURCE_LOWER_PORT_UNSPECIFIED,
138 AclConstants.SOURCE_UPPER_PORT_UNSPECIFIED, AclConstants.DEST_LOWER_PORT_UNSPECIFIED,
139 AclConstants.DEST_UPPER_PORT_UNSPECIFIED, AclConstants.SOURCE_REMOTE_IP_PREFIX_UNSPECIFIED,
140 AclConstants.DEST_REMOTE_IP_PREFIX_SPECIFIED, (short) -1);
141 dataBrokerUtil.put(ImmutableIdentifiedAceBuilder.builder().sgUuid(SG_UUID_1).newRuleName(SR_UUID_1_1)
142 .newMatches(matches).newDirection(DirectionEgress.class).build());
143 matches = newMatch(AclConstants.SOURCE_LOWER_PORT_UNSPECIFIED, AclConstants.SOURCE_UPPER_PORT_UNSPECIFIED,
144 AclConstants.DEST_LOWER_PORT_UNSPECIFIED, AclConstants.DEST_UPPER_PORT_UNSPECIFIED,
145 AclConstants.SOURCE_REMOTE_IP_PREFIX_SPECIFIED, AclConstants.DEST_REMOTE_IP_PREFIX_UNSPECIFIED,
148 ImmutableIdentifiedAceBuilder.builder().sgUuid(SG_UUID_1).newRuleName(SR_UUID_1_2).newMatches(matches)
149 .newDirection(DirectionIngress.class).newRemoteGroupId(new Uuid(SG_UUID_1)).build());
151 putNewStateInterface(dataBroker, PORT_1, PORT_MAC_1);
152 putNewStateInterface(dataBroker, PORT_2, PORT_MAC_2);
154 AclServiceTestUtils.waitABit(asyncEventsWaiter);
157 newInterfaceWithEtherTypeAclCheck();
158 LOG.info("newInterfaceWithEtherTypeAcl - end");
161 abstract void newInterfaceWithEtherTypeAclCheck();
164 public void newInterfaceWithTcpDstAcl() throws Exception {
165 LOG.info("newInterfaceWithTcpDstAcl - start");
167 newAllowedAddressPair(PORT_1, Collections.singletonList(SG_UUID_1), Collections.singletonList(AAP_PORT_1));
168 newAllowedAddressPair(PORT_2, Collections.singletonList(SG_UUID_1), Collections.singletonList(AAP_PORT_2));
171 Matches matches = newMatch(AclConstants.SOURCE_LOWER_PORT_UNSPECIFIED,
172 AclConstants.SOURCE_UPPER_PORT_UNSPECIFIED, AclConstants.DEST_LOWER_PORT_HTTP,
173 AclConstants.DEST_UPPER_PORT_HTTP, AclConstants.SOURCE_REMOTE_IP_PREFIX_UNSPECIFIED,
174 AclConstants.DEST_REMOTE_IP_PREFIX_SPECIFIED, (short) NwConstants.IP_PROT_TCP);
175 dataBrokerUtil.put(ImmutableIdentifiedAceBuilder.builder().sgUuid(SG_UUID_1).newRuleName(SR_UUID_1_1)
176 .newMatches(matches).newDirection(DirectionEgress.class).newRemoteGroupId(new Uuid(SG_UUID_1)).build());
177 matches = newMatch(AclConstants.SOURCE_LOWER_PORT_UNSPECIFIED, AclConstants.SOURCE_UPPER_PORT_UNSPECIFIED,
178 AclConstants.DEST_LOWER_PORT_HTTP, AclConstants.DEST_UPPER_PORT_HTTP,
179 AclConstants.SOURCE_REMOTE_IP_PREFIX_SPECIFIED, AclConstants.DEST_REMOTE_IP_PREFIX_UNSPECIFIED,
180 (short) NwConstants.IP_PROT_TCP);
182 dataBrokerUtil.put(ImmutableIdentifiedAceBuilder.builder().sgUuid(SG_UUID_1).newRuleName(SR_UUID_1_2)
183 .newMatches(matches).newDirection(DirectionIngress.class).build());
186 putNewStateInterface(dataBroker, PORT_1, PORT_MAC_1);
187 putNewStateInterface(dataBroker, PORT_2, PORT_MAC_2);
189 AclServiceTestUtils.waitABit(asyncEventsWaiter);
192 newInterfaceWithTcpDstAclCheck();
193 LOG.info("newInterfaceWithTcpDstAcl - end");
196 abstract void newInterfaceWithTcpDstAclCheck();
200 public void newInterfaceWithUdpDstAcl() throws Exception {
201 LOG.info("newInterfaceWithUdpDstAcl - start");
203 newAllowedAddressPair(PORT_1, Collections.singletonList(SG_UUID_1), Collections.singletonList(AAP_PORT_1));
204 newAllowedAddressPair(PORT_2, Collections.singletonList(SG_UUID_1), Collections.singletonList(AAP_PORT_2));
206 Matches matches = newMatch(AclConstants.SOURCE_LOWER_PORT_UNSPECIFIED,
207 AclConstants.SOURCE_UPPER_PORT_UNSPECIFIED, AclConstants.DEST_LOWER_PORT_HTTP,
208 AclConstants.DEST_UPPER_PORT_HTTP, AclConstants.SOURCE_REMOTE_IP_PREFIX_UNSPECIFIED,
209 AclConstants.DEST_REMOTE_IP_PREFIX_SPECIFIED, (short) NwConstants.IP_PROT_UDP);
210 dataBrokerUtil.put(ImmutableIdentifiedAceBuilder.builder().sgUuid(SG_UUID_1).newRuleName(SR_UUID_1_1)
211 .newMatches(matches).newDirection(DirectionEgress.class).build());
213 matches = newMatch(AclConstants.SOURCE_LOWER_PORT_UNSPECIFIED, AclConstants.SOURCE_UPPER_PORT_UNSPECIFIED,
214 AclConstants.DEST_LOWER_PORT_HTTP, AclConstants.DEST_UPPER_PORT_HTTP,
215 AclConstants.SOURCE_REMOTE_IP_PREFIX_SPECIFIED, AclConstants.DEST_REMOTE_IP_PREFIX_UNSPECIFIED,
216 (short) NwConstants.IP_PROT_UDP);
218 ImmutableIdentifiedAceBuilder.builder().sgUuid(SG_UUID_1).newRuleName(SR_UUID_1_2).newMatches(matches)
219 .newDirection(DirectionIngress.class).newRemoteGroupId(new Uuid(SG_UUID_1)).build());
222 putNewStateInterface(dataBroker, PORT_1, PORT_MAC_1);
223 putNewStateInterface(dataBroker, PORT_2, PORT_MAC_2);
225 AclServiceTestUtils.waitABit(asyncEventsWaiter);
228 newInterfaceWithUdpDstAclCheck();
229 LOG.info("newInterfaceWithUdpDstAcl - end");
232 abstract void newInterfaceWithUdpDstAclCheck();
235 public void newInterfaceWithIcmpAcl() throws Exception {
236 LOG.info("newInterfaceWithIcmpAcl - start");
238 newAllowedAddressPair(PORT_1, Collections.singletonList(SG_UUID_1), Collections.singletonList(AAP_PORT_1));
239 newAllowedAddressPair(PORT_2, Collections.singletonList(SG_UUID_1), Collections.singletonList(AAP_PORT_2));
241 prepareInterfaceWithIcmpAcl();
244 putNewStateInterface(dataBroker, PORT_1, PORT_MAC_1);
245 putNewStateInterface(dataBroker, PORT_2, PORT_MAC_2);
247 AclServiceTestUtils.waitABit(asyncEventsWaiter);
250 newInterfaceWithIcmpAclCheck();
251 LOG.info("newInterfaceWithIcmpAcl - end");
254 abstract void newInterfaceWithIcmpAclCheck();
257 public void newInterfaceWithDstPortRange() throws Exception {
258 LOG.info("newInterfaceWithDstPortRange - start");
260 newAllowedAddressPair(PORT_1, Collections.singletonList(SG_UUID_1), Collections.singletonList(AAP_PORT_1));
262 Matches matches = newMatch(AclConstants.SOURCE_LOWER_PORT_UNSPECIFIED,
263 AclConstants.SOURCE_UPPER_PORT_UNSPECIFIED, 333, 777, AclConstants.SOURCE_REMOTE_IP_PREFIX_UNSPECIFIED,
264 AclConstants.DEST_REMOTE_IP_PREFIX_SPECIFIED, (short) NwConstants.IP_PROT_TCP);
265 dataBrokerUtil.put(ImmutableIdentifiedAceBuilder.builder().sgUuid(SG_UUID_1).newRuleName(SR_UUID_1_1)
266 .newMatches(matches).newDirection(DirectionEgress.class).build());
267 matches = newMatch(AclConstants.SOURCE_LOWER_PORT_UNSPECIFIED, AclConstants.SOURCE_UPPER_PORT_UNSPECIFIED, 2000,
268 2003, AclConstants.SOURCE_REMOTE_IP_PREFIX_SPECIFIED, AclConstants.DEST_REMOTE_IP_PREFIX_UNSPECIFIED,
269 (short) NwConstants.IP_PROT_UDP);
271 dataBrokerUtil.put(ImmutableIdentifiedAceBuilder.builder().sgUuid(SG_UUID_1).newRuleName(SR_UUID_1_2)
272 .newMatches(matches).newDirection(DirectionIngress.class).build());
275 putNewStateInterface(dataBroker, PORT_1, PORT_MAC_1);
277 AclServiceTestUtils.waitABit(asyncEventsWaiter);
280 newInterfaceWithDstPortRangeCheck();
281 LOG.info("newInterfaceWithDstPortRange - end");
284 abstract void newInterfaceWithDstPortRangeCheck();
287 public void newInterfaceWithDstAllPorts() throws Exception {
288 LOG.info("newInterfaceWithDstAllPorts - start");
290 newAllowedAddressPair(PORT_1, Collections.singletonList(SG_UUID_1), Collections.singletonList(AAP_PORT_1));
292 Matches matches = newMatch(AclConstants.SOURCE_LOWER_PORT_UNSPECIFIED,
293 AclConstants.SOURCE_UPPER_PORT_UNSPECIFIED, 1, 65535, AclConstants.SOURCE_REMOTE_IP_PREFIX_UNSPECIFIED,
294 AclConstants.DEST_REMOTE_IP_PREFIX_SPECIFIED, (short) NwConstants.IP_PROT_TCP);
295 dataBrokerUtil.put(ImmutableIdentifiedAceBuilder.builder().sgUuid(SG_UUID_1).newRuleName(SR_UUID_1_1)
296 .newMatches(matches).newDirection(DirectionEgress.class).build());
297 matches = newMatch(AclConstants.SOURCE_LOWER_PORT_UNSPECIFIED, AclConstants.SOURCE_UPPER_PORT_UNSPECIFIED, 1,
298 65535, AclConstants.SOURCE_REMOTE_IP_PREFIX_SPECIFIED, AclConstants.DEST_REMOTE_IP_PREFIX_UNSPECIFIED,
299 (short) NwConstants.IP_PROT_UDP);
301 dataBrokerUtil.put(ImmutableIdentifiedAceBuilder.builder().sgUuid(SG_UUID_1).newRuleName(SR_UUID_1_2)
302 .newMatches(matches).newDirection(DirectionIngress.class).build());
305 putNewStateInterface(dataBroker, PORT_1, PORT_MAC_1);
307 AclServiceTestUtils.waitABit(asyncEventsWaiter);
310 newInterfaceWithDstAllPortsCheck();
311 LOG.info("newInterfaceWithDstAllPorts - end");
314 abstract void newInterfaceWithDstAllPortsCheck();
317 public void newInterfaceWithTwoAclsHavingSameRules() throws Exception {
318 LOG.info("newInterfaceWithTwoAclsHavingSameRules - start");
320 newAllowedAddressPair(PORT_3, Arrays.asList(SG_UUID_1, SG_UUID_2), Collections.singletonList(AAP_PORT_3));
322 Matches icmpEgressMatches = newMatch(AclConstants.SOURCE_LOWER_PORT_UNSPECIFIED,
323 AclConstants.SOURCE_UPPER_PORT_UNSPECIFIED, AclConstants.DEST_LOWER_PORT_2,
324 AclConstants.DEST_UPPER_PORT_3, AclConstants.SOURCE_REMOTE_IP_PREFIX_UNSPECIFIED,
325 AclConstants.DEST_REMOTE_IP_PREFIX_SPECIFIED, (short) NwConstants.IP_PROT_ICMP);
326 Matches icmpIngressMatches = newMatch(AclConstants.SOURCE_LOWER_PORT_UNSPECIFIED,
327 AclConstants.SOURCE_UPPER_PORT_UNSPECIFIED, AclConstants.DEST_LOWER_PORT_2,
328 AclConstants.DEST_UPPER_PORT_3, AclConstants.SOURCE_REMOTE_IP_PREFIX_SPECIFIED,
329 AclConstants.DEST_REMOTE_IP_PREFIX_UNSPECIFIED, (short) NwConstants.IP_PROT_ICMP);
331 dataBrokerUtil.put(ImmutableIdentifiedAceBuilder.builder().sgUuid(SG_UUID_1).newRuleName(SR_UUID_1_1)
332 .newMatches(icmpEgressMatches).newDirection(DirectionEgress.class).build());
334 dataBrokerUtil.put(ImmutableIdentifiedAceBuilder.builder().sgUuid(SG_UUID_1).newRuleName(SR_UUID_1_2)
335 .newMatches(icmpIngressMatches).newDirection(DirectionIngress.class).build());
337 dataBrokerUtil.put(ImmutableIdentifiedAceBuilder.builder().sgUuid(SG_UUID_2).newRuleName(SR_UUID_2_1)
338 .newMatches(icmpEgressMatches).newDirection(DirectionEgress.class).build());
340 dataBrokerUtil.put(ImmutableIdentifiedAceBuilder.builder().sgUuid(SG_UUID_2).newRuleName(SR_UUID_2_2)
341 .newMatches(icmpIngressMatches).newDirection(DirectionIngress.class).build());
344 putNewStateInterface(dataBroker, PORT_3, PORT_MAC_3);
346 AclServiceTestUtils.waitABit(asyncEventsWaiter);
349 newInterfaceWithTwoAclsHavingSameRulesCheck();
350 LOG.info("newInterfaceWithTwoAclsHavingSameRules - end");
353 abstract void newInterfaceWithTwoAclsHavingSameRulesCheck();
356 public void newInterfaceWithIcmpAclHavingOverlappingMac() throws Exception {
357 newAllowedAddressPair(PORT_1, Collections.singletonList(SG_UUID_1), Collections.singletonList(AAP_PORT_1));
358 newAllowedAddressPair(PORT_2, Collections.singletonList(SG_UUID_1), Collections.singletonList(AAP_PORT_2));
360 prepareInterfaceWithIcmpAcl();
363 putNewStateInterface(dataBroker, PORT_1, PORT_MAC_1);
364 putNewStateInterface(dataBroker, PORT_2, PORT_MAC_1);
366 AclServiceTestUtils.waitABit(asyncEventsWaiter);
369 newInterfaceWithIcmpAclCheck();
373 * Test new interface with allowed-address-pair (AAP) having IP prefix 0.0.0.0/0.
375 * FIXME: This TC works locally but is failing in Jenkins, hence disabling TC for now. This is related to ordering
376 * issue (with FlowEntity objects) with test infra (AssertDataObjects.assertEqualBeans) which needs to be fixed.
384 public void newInterfaceWithAapIpv4All() throws Exception {
385 LOG.info("newInterfaceWithAapIpv4All test - start");
387 newAllowedAddressPair(PORT_1, Collections.singletonList(SG_UUID_1), Collections.singletonList(AAP_PORT_1));
388 newAllowedAddressPair(PORT_2, Collections.singletonList(SG_UUID_1),
389 Arrays.asList(AAP_PORT_2, buildAap(AclConstants.IPV4_ALL_NETWORK, PORT_MAC_2)));
391 prepareInterfaceWithIcmpAcl();
393 putNewStateInterface(dataBroker, PORT_1, PORT_MAC_1);
394 putNewStateInterface(dataBroker, PORT_2, PORT_MAC_2);
396 AclServiceTestUtils.waitABit(asyncEventsWaiter);
399 newInterfaceWithAapIpv4AllCheck();
400 LOG.info("newInterfaceWithAapIpv4All test - end");
403 abstract void newInterfaceWithAapIpv4AllCheck();
406 public void newInterfaceWithAap() throws Exception {
407 LOG.info("newInterfaceWithAap test - start");
409 // AAP with same MAC and different IP
410 AllowedAddressPairs aapWithSameMac = buildAap("10.0.0.100/32", PORT_MAC_2);
411 // AAP with different MAC and different IP
412 AllowedAddressPairs aapWithDifferentMac = buildAap("10.0.0.101/32", "0D:AA:D8:42:30:A4");
414 newAllowedAddressPair(PORT_1, Collections.singletonList(SG_UUID_1), Collections.singletonList(AAP_PORT_1));
415 newAllowedAddressPair(PORT_2, Collections.singletonList(SG_UUID_1),
416 Arrays.asList(AAP_PORT_2, aapWithSameMac, aapWithDifferentMac));
418 prepareInterfaceWithIcmpAcl();
420 putNewStateInterface(dataBroker, PORT_1, PORT_MAC_1);
421 putNewStateInterface(dataBroker, PORT_2, PORT_MAC_2);
423 asyncEventsWaiter.awaitEventsConsumption();
426 newInterfaceWithAapCheck();
427 LOG.info("newInterfaceWithAap test - end");
430 abstract void newInterfaceWithAapCheck();
432 protected void assertFlowsInAnyOrder(Iterable<FlowEntity> expectedFlows) {
433 asyncEventsWaiter.awaitEventsConsumption();
434 coordinatorEventsWaiter.awaitEventsConsumption();
435 mdsalApiManager.assertFlowsInAnyOrder(expectedFlows);
438 protected void prepareInterfaceWithIcmpAcl() throws TransactionCommitFailedException {
440 Matches matches = newMatch(AclConstants.SOURCE_LOWER_PORT_UNSPECIFIED,
441 AclConstants.SOURCE_UPPER_PORT_UNSPECIFIED, AclConstants.DEST_LOWER_PORT_2,
442 AclConstants.DEST_UPPER_PORT_3, AclConstants.SOURCE_REMOTE_IP_PREFIX_UNSPECIFIED,
443 AclConstants.DEST_REMOTE_IP_PREFIX_SPECIFIED, (short) NwConstants.IP_PROT_ICMP);
444 dataBrokerUtil.put(ImmutableIdentifiedAceBuilder.builder().sgUuid(SG_UUID_1).newRuleName(SR_UUID_1_1)
445 .newMatches(matches).newDirection(DirectionEgress.class).newRemoteGroupId(new Uuid(SG_UUID_1)).build());
447 matches = newMatch(AclConstants.SOURCE_LOWER_PORT_UNSPECIFIED, AclConstants.SOURCE_UPPER_PORT_UNSPECIFIED,
448 AclConstants.DEST_LOWER_PORT_2, AclConstants.DEST_UPPER_PORT_3,
449 AclConstants.SOURCE_REMOTE_IP_PREFIX_SPECIFIED, AclConstants.DEST_REMOTE_IP_PREFIX_UNSPECIFIED,
450 (short) NwConstants.IP_PROT_ICMP);
451 dataBrokerUtil.put(ImmutableIdentifiedAceBuilder.builder().sgUuid(SG_UUID_1).newRuleName(SR_UUID_1_2)
452 .newMatches(matches).newDirection(DirectionIngress.class).build());
455 protected void newAllowedAddressPair(String portName, List<String> sgUuidList, List<AllowedAddressPairs> aapList)
456 throws TransactionCommitFailedException {
457 List<Uuid> sgList = sgUuidList.stream().map(Uuid::new).collect(Collectors.toList());
459 dataBrokerUtil.put(ImmutableIdentifiedInterfaceWithAclBuilder.builder().interfaceName(portName)
460 .portSecurity(true).addAllNewSecurityGroups(sgList).addAllIfAllowedAddressPairs(aapList).build());
463 protected void newElan(String elanName, long elanId) throws TransactionCommitFailedException {
464 ElanInstance elan = new ElanInstanceBuilder().setElanInstanceName(elanName).setElanTag(5000L).build();
465 singleTransactionDataBroker.syncWrite(CONFIGURATION,
466 AclServiceUtils.getElanInstanceConfigurationDataPath(elanName), elan);
469 protected void newElanInterface(String elanName, String portName, boolean isWrite)
470 throws TransactionCommitFailedException {
471 ElanInterface elanInterface =
472 new ElanInterfaceBuilder().setName(portName).setElanInstanceName(elanName).build();
473 InstanceIdentifier<ElanInterface> id = AclServiceUtils.getElanInterfaceConfigurationDataPathId(portName);
475 singleTransactionDataBroker.syncWrite(CONFIGURATION, id, elanInterface);
477 singleTransactionDataBroker.syncDelete(CONFIGURATION, id);
481 // TODO refactor this instead of stealing it from org.opendaylight.netvirt.neutronvpn.NeutronSecurityRuleListener
482 protected Matches newMatch(int srcLowerPort, int srcUpperPort, int destLowerPort, int destupperPort,
483 int srcRemoteIpPrefix, int dstRemoteIpPrefix, short protocol) {
485 AceIpBuilder aceIpBuilder = new AceIpBuilder();
486 if (destLowerPort != -1) {
487 DestinationPortRangeBuilder destinationPortRangeBuilder = new DestinationPortRangeBuilder();
488 destinationPortRangeBuilder.setLowerPort(new PortNumber(destLowerPort));
489 destinationPortRangeBuilder.setUpperPort(new PortNumber(destupperPort));
490 aceIpBuilder.setDestinationPortRange(destinationPortRangeBuilder.build());
492 AceIpv4Builder aceIpv4Builder = new AceIpv4Builder();
493 if (srcRemoteIpPrefix == AclConstants.SOURCE_REMOTE_IP_PREFIX_SPECIFIED) {
494 aceIpv4Builder.setSourceIpv4Network(new Ipv4Prefix(AclConstants.IPV4_ALL_NETWORK));
496 if (dstRemoteIpPrefix == AclConstants.DEST_REMOTE_IP_PREFIX_SPECIFIED) {
497 aceIpv4Builder.setSourceIpv4Network(new Ipv4Prefix(AclConstants.IPV4_ALL_NETWORK));
499 if (protocol != -1) {
500 aceIpBuilder.setProtocol(protocol);
502 aceIpBuilder.setAceIpVersion(aceIpv4Builder.build());
504 MatchesBuilder matchesBuilder = new MatchesBuilder();
505 matchesBuilder.setAceType(aceIpBuilder.build());
506 return matchesBuilder.build();
509 protected static AllowedAddressPairs buildAap(String ipAddress, String macAddress) {
510 return new AllowedAddressPairsBuilder()
511 .setIpAddress(new IpPrefixOrAddress(new IpPrefix(ipAddress.toCharArray())))
512 .setMacAddress(new MacAddress(macAddress)).build();
515 protected void setUpData() throws Exception {
516 newElan(ELAN, ELAN_TAG);
517 newElanInterface(ELAN, PORT_1, true);
518 newElanInterface(ELAN, PORT_2, true);
519 newElanInterface(ELAN, PORT_3, true);
520 newElanInterface(ELAN, PORT_4, true);