Search in sources :

Example 6 with SubnetInfo

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.interfaces._interface.SubnetInfo 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.@Nullable Interface interfaceState) {
    AclInterface aclInterface = aclInterfaceCache.addOrUpdate(interfaceId, (prevAclInterface, builder) -> {
        List<Uuid> sgs = new ArrayList<>();
        if (aclInPort != null) {
            sgs = aclInPort.getSecurityGroups();
            builder.portSecurityEnabled(aclInPort.isPortSecurityEnabled()).interfaceType(aclInPort.getInterfaceType()).securityGroups(sgs).allowedAddressPairs(new ArrayList<AllowedAddressPairs>(aclInPort.nonnullAllowedAddressPairs().values())).subnetInfo(new ArrayList<SubnetInfo>(aclInPort.nonnullSubnetInfo().values()));
        }
        if ((prevAclInterface == null || prevAclInterface.getLPortTag() == null) && interfaceState != null) {
            builder.dpId(AclServiceUtils.getDpIdFromIterfaceState(interfaceState)).lPortTag(interfaceState.getIfIndex()).isMarkedForDelete(false);
        }
        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) SubnetInfo(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.interfaces._interface.SubnetInfo)

Example 7 with SubnetInfo

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.interfaces._interface.SubnetInfo in project netvirt by opendaylight.

the class VirtualPort method getIpv6Addresses.

@Override
public List<Ipv6Address> getIpv6Addresses() {
    List<Ipv6Address> ipv6AddrList = snetInfo.values().stream().flatMap(subnetInfo -> Stream.of(subnetInfo.getIpAddr().getIpv6Address())).collect(Collectors.toList());
    if (deviceOwner.equalsIgnoreCase(Ipv6ServiceConstants.NETWORK_ROUTER_INTERFACE)) {
        Ipv6Address llAddr = Ipv6Util.getIpv6LinkLocalAddressFromMac(new MacAddress(macAddress));
        ipv6AddrList.add(llAddr);
    }
    return ipv6AddrList;
}
Also used : Timeout(io.netty.util.Timeout) Ipv6Util(org.opendaylight.genius.ipv6util.api.Ipv6Util) Ipv6ServiceConstants(org.opendaylight.netvirt.ipv6service.utils.Ipv6ServiceConstants) Uint64(org.opendaylight.yangtools.yang.common.Uint64) Logger(org.slf4j.Logger) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) IVirtualPort(org.opendaylight.netvirt.ipv6service.api.IVirtualPort) LoggerFactory(org.slf4j.LoggerFactory) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) Collectors(java.util.stream.Collectors) Ipv6PeriodicTimer(org.opendaylight.netvirt.ipv6service.utils.Ipv6PeriodicTimer) ArrayList(java.util.ArrayList) ConcurrentMap(java.util.concurrent.ConcurrentMap) List(java.util.List) Stream(java.util.stream.Stream) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) Ipv6PeriodicTrQueue(org.opendaylight.netvirt.ipv6service.utils.Ipv6PeriodicTrQueue) MacAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress) Ipv6Address(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address) MacAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress) Ipv6Address(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address)

Example 8 with SubnetInfo

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.interfaces._interface.SubnetInfo in project netvirt by opendaylight.

the class NaptManager method registerMapping.

// 1. napt service functions
/**
 * This method is used to inform this service of what external IP address to be used
 * as mapping when requested one for the internal IP address given in the input.
 *
 * @param segmentId – segmentation in which the mapping to be used. Eg; routerid
 * @param internal  subnet prefix or ip address
 * @param external  subnet prefix or ip address
 */
public void registerMapping(Uint32 segmentId, IPAddress internal, IPAddress external) {
    LOG.debug("registerMapping : called with segmentid {}, internalIp {}, prefix {}, externalIp {} " + "and prefix {} ", segmentId, internal.getIpAddress(), internal.getPrefixLength(), external.getIpAddress(), external.getPrefixLength());
    // Create Pool per ExternalIp and not for all IPs in the subnet.
    // Create new Pools during getExternalAddressMapping if exhausted.
    String externalIpPool;
    // subnet case
    if (external.getPrefixLength() != 0 && external.getPrefixLength() != NatConstants.DEFAULT_PREFIX) {
        String externalSubnet = external.getIpAddress() + "/" + external.getPrefixLength();
        LOG.debug("registerMapping : externalSubnet is : {}", externalSubnet);
        SubnetUtils subnetUtils = new SubnetUtils(externalSubnet);
        SubnetInfo subnetInfo = subnetUtils.getInfo();
        externalIpPool = subnetInfo.getLowAddress();
    } else {
        // ip case
        externalIpPool = external.getIpAddress();
    }
    createNaptPortPool(externalIpPool);
    // Store the ip to ip map in Operational DS
    String internalIp = internal.getIpAddress();
    if (internal.getPrefixLength() != 0) {
        internalIp = internal.getIpAddress() + "/" + internal.getPrefixLength();
    }
    String externalIp = external.getIpAddress();
    if (external.getPrefixLength() != 0) {
        externalIp = external.getIpAddress() + "/" + external.getPrefixLength();
    }
    updateCounter(segmentId, externalIp, true);
    // update the actual ip-map
    IpMap ipm = new IpMapBuilder().withKey(new IpMapKey(internalIp)).setInternalIp(internalIp).setExternalIp(externalIp).build();
    MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.OPERATIONAL, getIpMapIdentifier(segmentId, internalIp), ipm);
    LOG.debug("registerMapping : registerMapping exit after updating DS with internalIP {}, externalIP {}", internalIp, externalIp);
}
Also used : SubnetUtils(org.apache.commons.net.util.SubnetUtils) IpMapKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.ip.mapping.IpMapKey) SubnetInfo(org.apache.commons.net.util.SubnetUtils.SubnetInfo) IpMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.ip.mapping.IpMap) IntextIpMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.IntextIpMap) IpMapBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.ip.mapping.IpMapBuilder)

Example 9 with SubnetInfo

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.interfaces._interface.SubnetInfo in project netvirt by opendaylight.

the class NaptManager method checkIpMap.

@Nullable
protected String checkIpMap(Uint32 segmentId, String internalIp) {
    LOG.debug("checkIpMap : called with segmentId {} and internalIp {}", segmentId, internalIp);
    String externalIp;
    // check if ip-map node is there
    InstanceIdentifierBuilder<IpMapping> idBuilder = InstanceIdentifier.builder(IntextIpMap.class).child(IpMapping.class, new IpMappingKey(segmentId));
    InstanceIdentifier<IpMapping> id = idBuilder.build();
    Optional<IpMapping> ipMapping = Optional.empty();
    try {
        ipMapping = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, id);
    } catch (ExecutionException | InterruptedException e) {
        LOG.error("checkIpMap: Exception while reading IpMapping DS for the segmentId {} internalIp {}", segmentId, internalIp, e);
    }
    if (ipMapping.isPresent()) {
        for (IpMap ipMap : ipMapping.get().nonnullIpMap().values()) {
            if (Objects.equals(ipMap.getInternalIp(), internalIp)) {
                LOG.debug("checkIpMap : IpMap : {}", ipMap);
                externalIp = ipMap.getExternalIp();
                LOG.debug("checkIpMap : successfully returning externalIp {}", externalIp);
                return externalIp;
            } else if (ipMap.getInternalIp().contains("/")) {
                // subnet case
                SubnetUtils subnetUtils = new SubnetUtils(ipMap.getInternalIp());
                SubnetInfo subnetInfo = subnetUtils.getInfo();
                if (subnetInfo.isInRange(internalIp)) {
                    LOG.debug("checkIpMap : internalIp {} found to be IpMap of internalIpSubnet {}", internalIp, ipMap.getInternalIp());
                    externalIp = ipMap.getExternalIp();
                    LOG.debug("checkIpMap : checkIpMap successfully returning externalIp {}", externalIp);
                    return externalIp;
                }
            }
        }
    }
    // return null if not found
    LOG.error("checkIpMap : failed, returning NULL for segmentId {} and internalIp {}", segmentId, internalIp);
    return null;
}
Also used : SubnetUtils(org.apache.commons.net.util.SubnetUtils) IpMapping(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.IpMapping) IpMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.ip.mapping.IpMap) IntextIpMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.IntextIpMap) IntextIpMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.IntextIpMap) IpMappingKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.IpMappingKey) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) ExecutionException(java.util.concurrent.ExecutionException) SubnetInfo(org.apache.commons.net.util.SubnetUtils.SubnetInfo) Nullable(org.eclipse.jdt.annotation.Nullable)

Example 10 with SubnetInfo

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.interfaces._interface.SubnetInfo in project netvirt by opendaylight.

the class NeutronvpnUtils method getSubnetInfo.

@Nullable
protected List<SubnetInfo> getSubnetInfo(Port port) {
    Map<FixedIpsKey, FixedIps> keyFixedIpsMap = port.getFixedIps();
    if (keyFixedIpsMap == null) {
        LOG.error("Failed to get Fixed IPs for the port {}", port.getName());
        return null;
    }
    List<SubnetInfo> subnetInfoList = new ArrayList<>();
    for (FixedIps portFixedIp : keyFixedIpsMap.values()) {
        Uuid subnetId = portFixedIp.getSubnetId();
        Subnet subnet = getNeutronSubnet(subnetId);
        if (subnet != null) {
            Class<? extends IpVersionBase> ipVersion = NeutronSecurityGroupConstants.IP_VERSION_MAP.get(subnet.getIpVersion());
            Class<? extends Dhcpv6Base> raMode = subnet.getIpv6RaMode() == null ? null : NeutronSecurityGroupConstants.RA_MODE_MAP.get(subnet.getIpv6RaMode());
            SubnetInfo subnetInfo = new SubnetInfoBuilder().withKey(new SubnetInfoKey(subnetId)).setIpVersion(ipVersion).setIpPrefix(new IpPrefixOrAddress(subnet.getCidr())).setIpv6RaMode(raMode).setGatewayIp(subnet.getGatewayIp()).build();
            subnetInfoList.add(subnetInfo);
        }
    }
    return subnetInfoList;
}
Also used : IpPrefixOrAddress(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.IpPrefixOrAddress) ArrayList(java.util.ArrayList) SubnetInfoKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.interfaces._interface.SubnetInfoKey) SubnetInfoBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.interfaces._interface.SubnetInfoBuilder) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) FixedIpsKey(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes.FixedIpsKey) FixedIps(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes.FixedIps) Subnet(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.Subnet) SubnetInfo(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.interfaces._interface.SubnetInfo) Nullable(org.eclipse.jdt.annotation.Nullable)

Aggregations

ArrayList (java.util.ArrayList)5 SubnetInfo (org.apache.commons.net.util.SubnetUtils.SubnetInfo)5 SubnetUtils (org.apache.commons.net.util.SubnetUtils)4 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)4 IntextIpMap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.IntextIpMap)4 IpMap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.ip.mapping.IpMap)4 SubnetInfo (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.interfaces._interface.SubnetInfo)3 Nullable (org.eclipse.jdt.annotation.Nullable)2 AclInterface (org.opendaylight.netvirt.aclservice.api.utils.AclInterface)2 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)2 IpPrefixOrAddress (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.IpPrefixOrAddress)2 IpMapping (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.IpMapping)2 IpMappingKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.IpMappingKey)2 IpMapBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.ip.mapping.IpMapBuilder)2 IpMapKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.ip.mapping.IpMapKey)2 Uint64 (org.opendaylight.yangtools.yang.common.Uint64)2 UncheckedExecutionException (com.google.common.util.concurrent.UncheckedExecutionException)1 Timeout (io.netty.util.Timeout)1 List (java.util.List)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1