2 * Copyright (c) 2016 Cisco Systems, 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
9 package org.opendaylight.groupbasedpolicy.renderer.vpp.policy.acl;
11 import java.util.List;
12 import java.util.stream.Collectors;
14 import org.junit.Assert;
15 import org.junit.Before;
16 import org.junit.Test;
17 import org.mockito.Mockito;
18 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
19 import org.opendaylight.groupbasedpolicy.renderer.vpp.iface.InterfaceManager;
20 import org.opendaylight.groupbasedpolicy.renderer.vpp.policy.PolicyContext;
21 import org.opendaylight.groupbasedpolicy.renderer.vpp.util.MountedDataBrokerProvider;
22 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
24 import com.google.common.base.Optional;
26 public class AccessListUtilTest extends TestResources {
28 private PolicyContext ctx;
29 private MountedDataBrokerProvider mountedDataProviderMock;
30 private DataBroker mountPointDataBroker;
34 ctx = super.createPolicyContext(createAddressEndpoints(), createRendEps(), createRuleGroups(),
36 mountedDataProviderMock = Mockito.mock(MountedDataBrokerProvider.class);
37 mountPointDataBroker = Mockito.mock(DataBroker.class);
38 Mockito.when(mountedDataProviderMock.resolveDataBrokerForMountPoint(Mockito.any(InstanceIdentifier.class)))
39 .thenReturn(Optional.of(mountPointDataBroker));
43 public void resolveAclsOnInterfaceTest() throws Exception {
44 AclManager aclManager = new AclManager(mountedDataProviderMock, Mockito.mock(InterfaceManager.class));
45 List<AccessListWrapper> acls =
46 aclManager.resolveAclsOnInterface(rendererEndpointKey(l3AddrEp2.getKey()), ctx).get();
47 Assert.assertEquals(2, acls.size());
48 Assert.assertEquals(2, acls.stream().map(AccessListWrapper::getDirection).collect(Collectors.toSet()).size());
49 acls.stream().forEach(ace -> {
50 // allow peer + deny rest of tenant net + permit external
51 if (ace instanceof IngressAccessListWrapper) {
52 Assert.assertEquals(4, ace.readRules().size());
53 } else if (ace instanceof EgressAccessListWrapper) {
54 Assert.assertEquals(4, ace.readRules().size());