Search in sources :

Example 31 with SegmentId

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.sr.rev130819.SegmentId in project netvirt by opendaylight.

the class NaptManager method removeFromIpPortMapDS.

protected void removeFromIpPortMapDS(Uint32 segmentId, String internalIpPort, ProtocolTypes protocolType) {
    InstanceIdentifierBuilder<IpPortMap> idBuilder = InstanceIdentifier.builder(IntextIpPortMap.class).child(IpPortMapping.class, new IpPortMappingKey(segmentId)).child(IntextIpProtocolType.class, new IntextIpProtocolTypeKey(protocolType)).child(IpPortMap.class, new IpPortMapKey(internalIpPort));
    InstanceIdentifier<IpPortMap> id = idBuilder.build();
    // remove from ipportmap DS
    LOG.debug("removeFromIpPortMapDS : Removing ipportmap from datastore : {}", id);
    MDSALUtil.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION, id);
}
Also used : SnatintIpPortMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.SnatintIpPortMap) IntextIpPortMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.IntextIpPortMap) IpPortMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.port.map.ip.port.mapping.intext.ip.protocol.type.IpPortMap) IpPortMapKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.port.map.ip.port.mapping.intext.ip.protocol.type.IpPortMapKey) IpPortMappingKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.port.map.IpPortMappingKey) IntextIpProtocolType(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.port.map.ip.port.mapping.IntextIpProtocolType) IntextIpPortMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.IntextIpPortMap) IntextIpProtocolTypeKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.port.map.ip.port.mapping.IntextIpProtocolTypeKey)

Example 32 with SegmentId

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.sr.rev130819.SegmentId in project netvirt by opendaylight.

the class NaptManager method updateCounter.

public void updateCounter(Uint32 segmentId, String externalIp, boolean isAdd) {
    short counter = 0;
    InstanceIdentifier<ExternalIpCounter> id = InstanceIdentifier.builder(ExternalIpsCounter.class).child(ExternalCounters.class, new ExternalCountersKey(segmentId)).child(ExternalIpCounter.class, new ExternalIpCounterKey(externalIp)).build();
    Optional<ExternalIpCounter> externalIpCounter = Optional.empty();
    try {
        externalIpCounter = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.OPERATIONAL, id);
    } catch (ExecutionException | InterruptedException e) {
        LOG.error("updateCounter: Exception while reading ExternalIpCounter DS for the segmentId {} externalIp {} ", segmentId, externalIp, e);
    }
    if (externalIpCounter.isPresent()) {
        counter = externalIpCounter.get().getCounter().toJava();
        if (isAdd) {
            counter++;
            LOG.debug("updateCounter : externalIp and counter after increment are {} and {}", externalIp, counter);
        } else {
            if (counter > 0) {
                counter--;
            }
            LOG.debug("updateCounter : externalIp and counter after decrement are {} and {}", externalIp, counter);
        }
    } else if (isAdd) {
        counter = 1;
    }
    // update the new counter value for this externalIp
    ExternalIpCounter externalIpCounterData = new ExternalIpCounterBuilder().withKey(new ExternalIpCounterKey(externalIp)).setExternalIp(externalIp).setCounter(counter).build();
    MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.OPERATIONAL, getExternalIpsIdentifier(segmentId, externalIp), externalIpCounterData);
}
Also used : ExternalCountersKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.ips.counter.ExternalCountersKey) ExternalIpCounter(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.ips.counter.external.counters.ExternalIpCounter) ExternalIpCounterBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.ips.counter.external.counters.ExternalIpCounterBuilder) ExternalIpCounterKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.ips.counter.external.counters.ExternalIpCounterKey) ExternalIpsCounter(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExternalIpsCounter) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) ExecutionException(java.util.concurrent.ExecutionException)

Example 33 with SegmentId

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.sr.rev130819.SegmentId 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 34 with SegmentId

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.sr.rev130819.SegmentId in project netvirt by opendaylight.

the class NaptManager method removeFromSnatIpPortDS.

protected void removeFromSnatIpPortDS(Uint32 segmentId, String internalIp) {
    InstanceIdentifier<IpPort> intIp = InstanceIdentifier.builder(SnatintIpPortMap.class).child(IntipPortMap.class, new IntipPortMapKey(segmentId)).child(IpPort.class, new IpPortKey(internalIp)).build();
    // remove from SnatIpPortDS
    LOG.debug("removeFromSnatIpPortDS : Removing SnatIpPort from datastore : {}", intIp);
    MDSALUtil.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION, intIp);
}
Also used : SnatintIpPortMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.SnatintIpPortMap) IpPortKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.snatint.ip.port.map.intip.port.map.IpPortKey) IpPort(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.snatint.ip.port.map.intip.port.map.IpPort) IntipPortMapKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.snatint.ip.port.map.IntipPortMapKey)

Example 35 with SegmentId

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.topology.sr.rev130819.SegmentId in project netvirt by opendaylight.

the class NaptManager method releaseIpExtPortMapping.

// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
protected void releaseIpExtPortMapping(Uint32 segmentId, SessionAddress address, NAPTEntryEvent.Protocol protocol) {
    String internalIpPort = address.getIpAddress() + ":" + address.getPortNumber();
    SessionAddress existingIpPort = checkIpPortMap(segmentId, internalIpPort, protocol);
    if (existingIpPort != null) {
        // delete the entry from IpPortMap DS
        try {
            removeFromIpPortMapDS(segmentId, internalIpPort, protocol);
            // Finally release port from idmanager
            Uint32 releasedId = NatUtil.releaseId(idManager, existingIpPort.getIpAddress(), internalIpPort);
            if (releasedId == NatConstants.INVALID_ID) {
                LOG.error("releaseIpExtPortMapping : Unable to release ID for key {}", existingIpPort.getIpAddress());
            }
        } catch (Exception e) {
            LOG.error("releaseIpExtPortMapping : failed, Removal of ipportmap {} for " + "router {} failed", internalIpPort, segmentId, e);
        }
    } else {
        LOG.error("releaseIpExtPortMapping : failed, segmentId {} and " + "internalIpPort {} not found in IpPortMap DS", segmentId, internalIpPort);
    }
    // delete the entry of port for InternalIp from snatIntIpportMappingDS
    ProtocolTypes protocolType = NatUtil.getProtocolType(protocol);
    final ReentrantLock lock = lockFor(segmentId, address.getIpAddress(), protocolType);
    lock.lock();
    try {
        removeSnatIntIpPortDS(segmentId, address, protocolType);
    } catch (Exception e) {
        LOG.error("releaseSnatIpPortMapping : failed, Removal of snatipportmap {} for router {} failed", address.getIpAddress(), segmentId, e);
    } finally {
        lock.unlock();
    }
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) ProtocolTypes(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProtocolTypes) Uint32(org.opendaylight.yangtools.yang.common.Uint32) UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

ExecutionException (java.util.concurrent.ExecutionException)13 IntextIpMap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.IntextIpMap)12 IpMap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.ip.mapping.IpMap)12 UncheckedExecutionException (com.google.common.util.concurrent.UncheckedExecutionException)11 IpMapping (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.IpMapping)10 IpMappingKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.IpMappingKey)10 ProtocolTypes (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ProtocolTypes)8 SnatintIpPortMap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.SnatintIpPortMap)8 IpMapKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.ip.mapping.IpMapKey)8 Nullable (org.eclipse.jdt.annotation.Nullable)7 ArrayList (java.util.ArrayList)6 SubnetUtils (org.apache.commons.net.util.SubnetUtils)6 IntextIpPortMap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.IntextIpPortMap)6 IpPortMap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.port.map.ip.port.mapping.intext.ip.protocol.type.IpPortMap)6 IpPortMapKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.port.map.ip.port.mapping.intext.ip.protocol.type.IpPortMapKey)6 ActionInfo (org.opendaylight.genius.mdsalutil.ActionInfo)4 InstructionInfo (org.opendaylight.genius.mdsalutil.InstructionInfo)4 ActionSetDestinationIp (org.opendaylight.genius.mdsalutil.actions.ActionSetDestinationIp)4 InstructionApplyActions (org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions)4 InstructionGotoTable (org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable)4