Search in sources :

Example 41 with Acl

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.Acl in project netvirt by opendaylight.

the class IngressAclServiceImpl method bindService.

/**
 * Bind service.
 *
 * @param aclInterface the acl interface
 */
@Override
public void bindService(AclInterface aclInterface) {
    String interfaceName = aclInterface.getInterfaceId();
    jobCoordinator.enqueueJob(interfaceName, () -> {
        int instructionKey = 0;
        List<Instruction> instructions = new ArrayList<>();
        instructions.add(MDSALUtil.buildAndGetGotoTableInstruction(NwConstants.EGRESS_ACL_DUMMY_TABLE, ++instructionKey));
        int flowPriority = NwConstants.EGRESS_ACL_SERVICE_INDEX;
        short serviceIndex = ServiceIndex.getIndex(NwConstants.EGRESS_ACL_SERVICE_NAME, NwConstants.EGRESS_ACL_SERVICE_INDEX);
        BoundServices serviceInfo = AclServiceUtils.getBoundServices(String.format("%s.%s.%s", "acl", "egressacl", interfaceName), serviceIndex, flowPriority, AclConstants.COOKIE_ACL_BASE, instructions);
        InstanceIdentifier<BoundServices> path = AclServiceUtils.buildServiceId(interfaceName, ServiceIndex.getIndex(NwConstants.EGRESS_ACL_SERVICE_NAME, NwConstants.EGRESS_ACL_SERVICE_INDEX), serviceMode);
        return Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> tx.put(LogicalDatastoreType.CONFIGURATION, path, serviceInfo, WriteTransaction.CREATE_MISSING_PARENTS)));
    });
}
Also used : LoggerFactory(org.slf4j.LoggerFactory) MatchInfoBase(org.opendaylight.genius.mdsalutil.MatchInfoBase) AclServiceUtils(org.opendaylight.netvirt.aclservice.utils.AclServiceUtils) ArrayList(java.util.ArrayList) MatchEthernetDestination(org.opendaylight.genius.mdsalutil.matches.MatchEthernetDestination) ServiceIndex(org.opendaylight.genius.utils.ServiceIndex) AllowedAddressPairs(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.interfaces._interface.AllowedAddressPairs) AclInterfaceCache(org.opendaylight.netvirt.aclservice.api.AclInterfaceCache) MatchEthernetType(org.opendaylight.genius.mdsalutil.matches.MatchEthernetType) BigInteger(java.math.BigInteger) NwConstants(org.opendaylight.genius.mdsalutil.NwConstants) MDSALUtil(org.opendaylight.genius.mdsalutil.MDSALUtil) MacAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress) AclServiceOFFlowBuilder(org.opendaylight.netvirt.aclservice.utils.AclServiceOFFlowBuilder) ServiceModeEgress(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.servicebinding.rev160406.ServiceModeEgress) DirectionBase(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.DirectionBase) DirectionIngress(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.DirectionIngress) AclInterface(org.opendaylight.netvirt.aclservice.api.utils.AclInterface) MatchCriteria(org.opendaylight.netvirt.aclservice.api.AclServiceManager.MatchCriteria) BoundServices(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.servicebinding.rev160406.service.bindings.services.info.BoundServices) Logger(org.slf4j.Logger) AclConstants(org.opendaylight.netvirt.aclservice.utils.AclConstants) AclDataUtil(org.opendaylight.netvirt.aclservice.utils.AclDataUtil) LogicalDatastoreType(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType) JobCoordinator(org.opendaylight.infrautils.jobcoordinator.JobCoordinator) WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) DataBroker(org.opendaylight.controller.md.sal.binding.api.DataBroker) List(java.util.List) InstructionInfo(org.opendaylight.genius.mdsalutil.InstructionInfo) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier) IMdsalApiManager(org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager) InstructionGotoTable(org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable) Action(org.opendaylight.netvirt.aclservice.api.AclServiceManager.Action) IpPrefixOrAddress(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.IpPrefixOrAddress) Collections(java.util.Collections) Instruction(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction) BoundServices(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.servicebinding.rev160406.service.bindings.services.info.BoundServices) ArrayList(java.util.ArrayList) Instruction(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction)

Example 42 with Acl

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.Acl in project netvirt by opendaylight.

the class AclElanInterfaceListener method add.

@Override
protected void add(InstanceIdentifier<ElanInterface> key, ElanInterface elanInterface) {
    String interfaceId = elanInterface.getName();
    AclInterface aclInterface = aclInterfaceCache.updateIfPresent(interfaceId, (prevAclInterface, builder) -> {
        if (prevAclInterface.getElanId() == null) {
            ElanInstance elanInfo = AclServiceUtils.getElanInstanceByName(elanInterface.getElanInstanceName(), dataBroker);
            builder.elanId(elanInfo.getElanTag());
            return true;
        }
        return false;
    });
    if (aclInterface == null) {
        LOG.debug("On Add event, ignore if AclInterface was not found in cache or was not updated");
        return;
    }
    if (aclInterface.getDpId() != null && aclClusterUtil.isEntityOwner()) {
        // Notify ADD flows, if InterfaceStateListener has processed before ELAN-ID getting populated
        LOG.debug("On add event, notify ACL service manager to BIND/ADD ACL for interface: {}", aclInterface);
        aclServiceManager.notify(aclInterface, null, Action.BIND);
        aclServiceManager.notify(aclInterface, null, Action.ADD);
    }
}
Also used : AclInterface(org.opendaylight.netvirt.aclservice.api.utils.AclInterface) ElanInstance(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.instances.ElanInstance)

Example 43 with Acl

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.Acl in project netvirt by opendaylight.

the class AclEventListener method getChangedAceList.

private List<Ace> getChangedAceList(Acl updatedAcl, Acl currentAcl) {
    if (updatedAcl == null) {
        return null;
    }
    List<Ace> updatedAceList = updatedAcl.getAccessListEntries() == null ? new ArrayList<>() : new ArrayList<>(updatedAcl.getAccessListEntries().getAce());
    if (currentAcl == null) {
        return updatedAceList;
    }
    List<Ace> currentAceList = currentAcl.getAccessListEntries() == null ? new ArrayList<>() : new ArrayList<>(currentAcl.getAccessListEntries().getAce());
    for (Iterator<Ace> iterator = updatedAceList.iterator(); iterator.hasNext(); ) {
        Ace ace1 = iterator.next();
        for (Ace ace2 : currentAceList) {
            if (ace1.getRuleName().equals(ace2.getRuleName())) {
                iterator.remove();
            }
        }
    }
    return updatedAceList;
}
Also used : Ace(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.Ace)

Example 44 with Acl

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.Acl in project netvirt by opendaylight.

the class AclInterfaceListener method addOrUpdateAclInterfaceCache.

private AclInterface addOrUpdateAclInterfaceCache(String interfaceId, InterfaceAcl aclInPort, boolean isSgChanged, org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface interfaceState) {
    AclInterface aclInterface = aclInterfaceCache.addOrUpdate(interfaceId, (prevAclInterface, builder) -> {
        List<Uuid> sgs = new ArrayList<>();
        if (aclInPort != null) {
            sgs = aclInPort.getSecurityGroups();
            builder.portSecurityEnabled(aclInPort.isPortSecurityEnabled()).securityGroups(sgs).allowedAddressPairs(aclInPort.getAllowedAddressPairs());
        }
        if ((prevAclInterface == null || prevAclInterface.getLPortTag() == null) && interfaceState != null) {
            builder.dpId(AclServiceUtils.getDpIdFromIterfaceState(interfaceState)).lPortTag(interfaceState.getIfIndex()).isMarkedForDelete(false);
        }
        if (prevAclInterface == null) {
            builder.subnetIpPrefixes(AclServiceUtils.getSubnetIpPrefixes(dataBroker, interfaceId));
        }
        if (prevAclInterface == null || prevAclInterface.getElanId() == null) {
            builder.elanId(AclServiceUtils.getElanIdFromInterface(interfaceId, dataBroker));
        }
        if (prevAclInterface == null || isSgChanged) {
            builder.ingressRemoteAclTags(aclServiceUtils.getRemoteAclTags(sgs, DirectionIngress.class)).egressRemoteAclTags(aclServiceUtils.getRemoteAclTags(sgs, DirectionEgress.class));
        }
    });
    // Clone and return the ACL interface object
    return AclInterface.builder(aclInterface).build();
}
Also used : AclInterface(org.opendaylight.netvirt.aclservice.api.utils.AclInterface) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) ArrayList(java.util.ArrayList) DirectionEgress(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.DirectionEgress)

Example 45 with Acl

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.Acl in project netvirt by opendaylight.

the class AclInterfaceListener method update.

@Override
public void update(InstanceIdentifier<Interface> key, Interface portBefore, Interface portAfter) {
    if (portBefore.getAugmentation(ParentRefs.class) == null && portAfter.getAugmentation(ParentRefs.class) != null) {
        LOG.trace("Ignoring event for update in ParentRefs for {} ", portAfter.getName());
        return;
    }
    LOG.trace("Received AclInterface update event, portBefore={}, portAfter={}", portBefore, portAfter);
    InterfaceAcl aclInPortAfter = portAfter.getAugmentation(InterfaceAcl.class);
    InterfaceAcl aclInPortBefore = portBefore.getAugmentation(InterfaceAcl.class);
    String interfaceId = portAfter.getName();
    org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface interfaceState = AclServiceUtils.getInterfaceStateFromOperDS(dataBroker, interfaceId);
    AclInterface aclInterfaceBefore = aclInterfaceCache.get(interfaceId);
    if (aclInterfaceBefore == null || isPortSecurityEnabledNow(aclInPortBefore, aclInPortAfter)) {
        // Updating cache now as it might have not updated when
        // port-security-enable=false
        aclInterfaceBefore = addOrUpdateAclInterfaceCache(interfaceId, aclInPortBefore, true, interfaceState);
    }
    if (aclInPortAfter != null && aclInPortAfter.isPortSecurityEnabled() || aclInPortBefore != null && aclInPortBefore.isPortSecurityEnabled()) {
        boolean isSgChanged = isSecurityGroupsChanged(aclInPortBefore.getSecurityGroups(), aclInPortAfter.getSecurityGroups());
        AclInterface aclInterfaceAfter = addOrUpdateAclInterfaceCache(interfaceId, aclInPortAfter, isSgChanged, interfaceState);
        if (aclClusterUtil.isEntityOwner()) {
            // Handle bind/unbind service irrespective of interface state (up/down)
            boolean isPortSecurityEnable = aclInterfaceAfter.isPortSecurityEnabled();
            boolean isPortSecurityEnableBefore = aclInterfaceBefore.isPortSecurityEnabled();
            // if port security enable is changed and is disabled, unbind ACL service
            if (isPortSecurityEnableBefore != isPortSecurityEnable && !isPortSecurityEnable) {
                LOG.debug("Notify unbind ACL service for interface={}, isPortSecurityEnable={}", interfaceId, isPortSecurityEnable);
                aclServiceManager.notify(aclInterfaceAfter, null, Action.UNBIND);
            }
            if (interfaceState != null && interfaceState.getOperStatus().equals(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.OperStatus.Up)) {
                // if port security enable is changed and is enabled, bind ACL service
                if (isPortSecurityEnableBefore != isPortSecurityEnable && isPortSecurityEnable) {
                    LOG.debug("Notify bind ACL service for interface={}, isPortSecurityEnable={}", interfaceId, isPortSecurityEnable);
                    aclServiceManager.notify(aclInterfaceAfter, null, Action.BIND);
                }
                LOG.debug("On update event, notify ACL service manager to update ACL for interface: {}", interfaceId);
                // handle add for AclPortsLookup before processing update
                try {
                    Futures.allAsList(aclServiceUtils.addAclPortsLookupForInterfaceUpdate(aclInterfaceBefore, aclInterfaceAfter)).get();
                } catch (InterruptedException | ExecutionException e) {
                    LOG.error("Error adding ACL ports for interface update", e);
                }
                aclServiceManager.notify(aclInterfaceAfter, aclInterfaceBefore, AclServiceManager.Action.UPDATE);
                // handle delete for AclPortsLookup after processing update
                try {
                    Futures.allAsList(aclServiceUtils.deleteAclPortsLookupForInterfaceUpdate(aclInterfaceBefore, aclInterfaceAfter)).get();
                } catch (InterruptedException | ExecutionException e) {
                    LOG.error("Error deleting ACL ports for interface update", e);
                }
            }
        }
        updateCacheWithAclChange(aclInterfaceBefore, aclInterfaceAfter);
    }
}
Also used : AclInterface(org.opendaylight.netvirt.aclservice.api.utils.AclInterface) InterfaceAcl(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.InterfaceAcl) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

ArrayList (java.util.ArrayList)27 MatchInfoBase (org.opendaylight.genius.mdsalutil.MatchInfoBase)19 AclInterface (org.opendaylight.netvirt.aclservice.api.utils.AclInterface)16 BigInteger (java.math.BigInteger)15 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)15 InstructionInfo (org.opendaylight.genius.mdsalutil.InstructionInfo)13 AllowedAddressPairs (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.interfaces._interface.AllowedAddressPairs)13 List (java.util.List)12 IpPrefixOrAddress (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.IpPrefixOrAddress)10 HashMap (java.util.HashMap)9 HashSet (java.util.HashSet)9 Ace (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.Ace)9 Set (java.util.Set)8 Acl (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.Acl)8 Collections (java.util.Collections)7 DataBroker (org.opendaylight.controller.md.sal.binding.api.DataBroker)7 MDSALUtil (org.opendaylight.genius.mdsalutil.MDSALUtil)7 NwConstants (org.opendaylight.genius.mdsalutil.NwConstants)7 InstructionGotoTable (org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable)7 MatchEthernetType (org.opendaylight.genius.mdsalutil.matches.MatchEthernetType)7