Search in sources :

Example 11 with SubnetOpDataEntry

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntry in project netvirt by opendaylight.

the class VpnSubnetRouteHandler method onInterfaceDown.

// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
public void onInterfaceDown(final BigInteger dpnId, final String interfaceName, Uuid subnetId) {
    if (dpnId == null || Objects.equals(dpnId, BigInteger.ZERO)) {
        LOG.error("{} onInterfaceDown: Unable to determine the DPNID for port {} on subnet {}", LOGGING_PREFIX, interfaceName, subnetId.getValue());
        return;
    }
    try {
        VpnUtil.lockSubnet(lockManager, subnetId.getValue());
        try {
            boolean last = subOpDpnManager.removeInterfaceFromDpn(subnetId, dpnId, interfaceName);
            InstanceIdentifier<SubnetOpDataEntry> subOpIdentifier = InstanceIdentifier.builder(SubnetOpData.class).child(SubnetOpDataEntry.class, new SubnetOpDataEntryKey(subnetId)).build();
            Optional<SubnetOpDataEntry> optionalSubs = VpnUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, subOpIdentifier);
            if (!optionalSubs.isPresent()) {
                LOG.info("{} onInterfaceDown: SubnetOpDataEntry for subnet {} is not available." + " Ignoring port {} down event.", LOGGING_PREFIX, subnetId.getValue(), interfaceName);
                return;
            }
            SubnetOpDataEntry subnetOpDataEntry = optionalSubs.get();
            SubnetOpDataEntryBuilder subOpBuilder = new SubnetOpDataEntryBuilder(subnetOpDataEntry);
            LOG.info("{} onInterfaceDown: Updating the SubnetOpDataEntry node for subnet {} subnetIp {}" + " vpnName {} rd {} TaskState {} lastTaskState {} on port {} down", LOGGING_PREFIX, subnetId.getValue(), subOpBuilder.getSubnetCidr(), subOpBuilder.getVpnName(), subOpBuilder.getVrfId(), subOpBuilder.getRouteAdvState(), subOpBuilder.getLastAdvState(), interfaceName);
            BigInteger nhDpnId = subOpBuilder.getNhDpnId();
            if (nhDpnId != null && nhDpnId.equals(dpnId)) {
                // select another NhDpnId
                if (last) {
                    LOG.debug("{} onInterfaceDown: Last active port {} on the subnet {} subnetIp {} vpn {}" + " rd {}", LOGGING_PREFIX, interfaceName, subnetId.getValue(), subOpBuilder.getSubnetCidr(), subOpBuilder.getVpnName(), subOpBuilder.getVrfId());
                    // last port on this DPN, so we need to elect the new NHDpnId
                    electNewDpnForSubnetRoute(subOpBuilder, dpnId, subnetId, null, /*networkId*/
                    !VpnUtil.isExternalSubnetVpn(subnetOpDataEntry.getVpnName(), subnetId.getValue()));
                    MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.OPERATIONAL, subOpIdentifier, subOpBuilder.build());
                    LOG.info("{} onInterfaceDown: Updated subnetopdataentry for subnet {} subnetIp {} vpnName {}" + " rd {} to OP Datastore on port {} down ", LOGGING_PREFIX, subnetId.getValue(), subOpBuilder.getSubnetCidr(), subOpBuilder.getVpnName(), subOpBuilder.getVrfId(), interfaceName);
                }
            }
        } catch (Exception ex) {
            LOG.error("{} onInterfaceDown: SubnetOpDataEntry update on interface {} down event for subnet {} failed", LOGGING_PREFIX, interfaceName, subnetId.getValue(), ex);
        } finally {
            VpnUtil.unlockSubnet(lockManager, subnetId.getValue());
        }
    } catch (RuntimeException e) {
        LOG.error("{} onInterfaceDown: Unable to handle interface down event for port {} in subnet {}", LOGGING_PREFIX, interfaceName, subnetId.getValue(), e);
    }
}
Also used : SubnetOpDataEntryBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntryBuilder) SubnetOpDataEntryKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntryKey) BigInteger(java.math.BigInteger) SubnetOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntry)

Example 12 with SubnetOpDataEntry

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntry in project netvirt by opendaylight.

the class VpnSubnetRouteHandler method onInterfaceUp.

// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
public void onInterfaceUp(BigInteger dpnId, String intfName, Uuid subnetId) {
    // TODO(vivek): Change this to use more granularized lock at subnetId level
    SubnetToDpn subDpn = null;
    if (dpnId == null || Objects.equals(dpnId, BigInteger.ZERO)) {
        LOG.error("{} onInterfaceUp: Unable to determine the DPNID for port {} on subnet {}", LOGGING_PREFIX, intfName, subnetId.getValue());
        return;
    }
    try {
        VpnUtil.lockSubnet(lockManager, subnetId.getValue());
        try {
            InstanceIdentifier<SubnetOpDataEntry> subOpIdentifier = InstanceIdentifier.builder(SubnetOpData.class).child(SubnetOpDataEntry.class, new SubnetOpDataEntryKey(subnetId)).build();
            Optional<SubnetOpDataEntry> optionalSubs = VpnUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, subOpIdentifier);
            if (!optionalSubs.isPresent()) {
                LOG.trace("{} onInterfaceUp: SubnetOpDataEntry for subnet {} is not available." + " Ignoring interfaceUp for port{}", LOGGING_PREFIX, subnetId.getValue(), intfName);
                return;
            }
            subOpDpnManager.addPortOpDataEntry(intfName, subnetId, dpnId);
            subDpn = subOpDpnManager.addInterfaceToDpn(subnetId, dpnId, intfName);
            if (subDpn == null) {
                return;
            }
            SubnetOpDataEntry subnetOpDataEntry = optionalSubs.get();
            SubnetOpDataEntryBuilder subOpBuilder = new SubnetOpDataEntryBuilder(subnetOpDataEntry);
            LOG.info("{} onInterfaceUp: Updating the SubnetOpDataEntry node for subnet {} subnetIp {} vpn {}" + " rd {} TaskState {} lastTaskState {}", LOGGING_PREFIX, subnetId.getValue(), subOpBuilder.getSubnetCidr(), subOpBuilder.getVpnName(), subOpBuilder.getVrfId(), subOpBuilder.getRouteAdvState(), subOpBuilder.getLastAdvState());
            boolean isExternalSubnetVpn = VpnUtil.isExternalSubnetVpn(subnetOpDataEntry.getVpnName(), subnetId.getValue());
            List<SubnetToDpn> subDpnList = subOpBuilder.getSubnetToDpn();
            subDpnList.add(subDpn);
            subOpBuilder.setSubnetToDpn(subDpnList);
            if (subOpBuilder.getRouteAdvState() != TaskState.Advertised) {
                if (subOpBuilder.getNhDpnId() == null) {
                    // No nexthop selected yet, elect one now
                    electNewDpnForSubnetRoute(subOpBuilder, null, /* oldDpnId */
                    subnetId, null, /*networkId*/
                    !isExternalSubnetVpn);
                } else if (!isExternalSubnetVpn) {
                    // Already nexthop has been selected, only publishing to bgp required, so publish to bgp
                    getNexthopTepAndPublishRoute(subOpBuilder, subnetId);
                }
            }
            SubnetOpDataEntry subOpEntry = subOpBuilder.build();
            MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.OPERATIONAL, subOpIdentifier, subOpEntry);
            LOG.info("{} onInterfaceUp: Updated subnetopdataentry to OP Datastore port {} up for subnet {}" + " subnetIp {} vpnName {} rd {} TaskState {} lastTaskState {} ", LOGGING_PREFIX, intfName, subnetId.getValue(), subOpEntry.getSubnetCidr(), subOpEntry.getVpnName(), subOpEntry.getVrfId(), subOpEntry.getRouteAdvState(), subOpEntry.getLastAdvState());
        } catch (Exception ex) {
            LOG.error("{} onInterfaceUp: Updation of SubnetOpDataEntry for subnet {} on port {} up failed", LOGGING_PREFIX, subnetId.getValue(), intfName, ex);
        } finally {
            VpnUtil.unlockSubnet(lockManager, subnetId.getValue());
        }
    } catch (RuntimeException e) {
        LOG.error("{} onInterfaceUp: Unable to handle interface up event for port {} in subnet {}", LOGGING_PREFIX, intfName, subnetId.getValue(), e);
    }
}
Also used : SubnetOpDataEntryBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntryBuilder) SubnetOpDataEntryKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntryKey) SubnetOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntry) SubnetToDpn(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.subnet.op.data.entry.SubnetToDpn)

Example 13 with SubnetOpDataEntry

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntry in project netvirt by opendaylight.

the class VpnSubnetRouteHandler method onPortRemovedFromSubnet.

// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
public void onPortRemovedFromSubnet(Subnetmap subnetmap, Uuid portId) {
    Uuid subnetId = subnetmap.getId();
    // TODO(vivek): Change this to use more granularized lock at subnetId level
    try {
        VpnUtil.lockSubnet(lockManager, subnetId.getValue());
        try {
            PortOpDataEntry portOpEntry = subOpDpnManager.removePortOpDataEntry(portId.getValue(), subnetmap.getId());
            if (portOpEntry == null) {
                return;
            }
            BigInteger dpnId = portOpEntry.getDpnId();
            if (dpnId == null) {
                LOG.error("{} onPortRemovedFromSubnet:  Port {} does not have a DPNId associated," + " ignoring removal from subnet {}", LOGGING_PREFIX, portId.getValue(), subnetId.getValue());
                return;
            }
            boolean last = subOpDpnManager.removeInterfaceFromDpn(subnetId, dpnId, portId.getValue());
            InstanceIdentifier<SubnetOpDataEntry> subOpIdentifier = InstanceIdentifier.builder(SubnetOpData.class).child(SubnetOpDataEntry.class, new SubnetOpDataEntryKey(subnetId)).build();
            Optional<SubnetOpDataEntry> optionalSubs = VpnUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, subOpIdentifier);
            if (!optionalSubs.isPresent()) {
                LOG.info("{} onPortRemovedFromSubnet: Port {} is part of a subnet {} that is not in VPN," + " ignoring", LOGGING_PREFIX, portId.getValue(), subnetId.getValue());
                return;
            }
            LOG.info("{} onPortRemovedFromSubnet: Port {} being removed. Updating the SubnetOpDataEntry" + " for subnet {} subnetIp {} vpnName {} rd {} TaskState {} lastTaskState {}", LOGGING_PREFIX, portId.getValue(), subnetId.getValue(), optionalSubs.get().getSubnetCidr(), optionalSubs.get().getVpnName(), optionalSubs.get().getVrfId(), optionalSubs.get().getRouteAdvState(), optionalSubs.get().getLastAdvState());
            SubnetOpDataEntry subnetOpDataEntry = optionalSubs.get();
            SubnetOpDataEntryBuilder subOpBuilder = new SubnetOpDataEntryBuilder(subnetOpDataEntry);
            BigInteger nhDpnId = subOpBuilder.getNhDpnId();
            if (nhDpnId != null && nhDpnId.equals(dpnId)) {
                // select another NhDpnId
                if (last) {
                    LOG.debug("{} onPortRemovedFromSubnet: Last port {} being removed from subnet {} subnetIp {}" + " vpnName {} rd {}", LOGGING_PREFIX, portId.getValue(), subnetId.getValue(), subOpBuilder.getSubnetCidr(), subOpBuilder.getVpnName(), subOpBuilder.getVrfId());
                    // last port on this DPN, so we need to elect the new NHDpnId
                    electNewDpnForSubnetRoute(subOpBuilder, nhDpnId, subnetId, subnetmap.getNetworkId(), !VpnUtil.isExternalSubnetVpn(subnetOpDataEntry.getVpnName(), subnetId.getValue()));
                    MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.OPERATIONAL, subOpIdentifier, subOpBuilder.build());
                    LOG.info("{} onPortRemovedFromSubnet: Updated subnetopdataentry to OP Datastore" + " removing port {} from subnet {} subnetIp {} vpnName {} rd {}", LOGGING_PREFIX, portId.getValue(), subnetId.getValue(), subOpBuilder.getSubnetCidr(), subOpBuilder.getVpnName(), subOpBuilder.getVrfId());
                }
            }
        } catch (RuntimeException ex) {
            LOG.error("{} onPortRemovedFromSubnet: Removal of portOp for {} from subnet {} failed", LOGGING_PREFIX, portId.getValue(), subnetId.getValue(), ex);
        } finally {
            VpnUtil.unlockSubnet(lockManager, subnetId.getValue());
        }
    } catch (RuntimeException e) {
        LOG.error("{} onPortRemovedFromSubnet: Unable to handle port {} removed from subnet {}", LOGGING_PREFIX, portId.getValue(), subnetId.getValue(), e);
    }
}
Also used : SubnetOpDataEntryBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntryBuilder) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) SubnetOpDataEntryKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntryKey) PortOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.port.op.data.PortOpDataEntry) BigInteger(java.math.BigInteger) SubnetOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntry)

Example 14 with SubnetOpDataEntry

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntry in project netvirt by opendaylight.

the class SubnetRoutePacketInHandler method getTargetSubnetForPacketOut.

// return only the first VPN subnetopdataentry
private static SubnetOpDataEntry getTargetSubnetForPacketOut(DataBroker broker, long elanTag, int ipAddress) {
    ElanTagName elanInfo = VpnUtil.getElanInfoByElanTag(broker, elanTag);
    if (elanInfo == null) {
        LOG.error("{} getTargetDpnForPacketOut: Unable to retrieve ElanInfo for elanTag {}", LOGGING_PREFIX, elanTag);
        return null;
    }
    Optional<NetworkMap> optionalNetworkMap = VpnUtil.read(broker, LogicalDatastoreType.CONFIGURATION, VpnUtil.buildNetworkMapIdentifier(new Uuid(elanInfo.getName())));
    if (!optionalNetworkMap.isPresent()) {
        LOG.debug("{} getTargetDpnForPacketOut: No network map found for elan info {}", LOGGING_PREFIX, elanInfo.getName());
        return null;
    }
    List<Uuid> subnetList = optionalNetworkMap.get().getSubnetIdList();
    LOG.debug("{} getTargetDpnForPacketOut: Obtained subnetList as {} for network {}", LOGGING_PREFIX, subnetList, elanInfo.getName());
    for (Uuid subnetId : subnetList) {
        String vpnName = null;
        Subnetmap sn = VpnUtil.getSubnetmapFromItsUuid(broker, subnetId);
        if (sn != null && sn.getVpnId() != null) {
            vpnName = sn.getVpnId().getValue();
        }
        if (vpnName == null) {
            continue;
        }
        Optional<SubnetOpDataEntry> optionalSubs;
        optionalSubs = VpnUtil.read(broker, LogicalDatastoreType.OPERATIONAL, VpnUtil.buildSubnetOpDataEntryInstanceIdentifier(subnetId));
        if (!optionalSubs.isPresent()) {
            continue;
        }
        SubnetOpDataEntry subOpEntry = optionalSubs.get();
        if (subOpEntry.getNhDpnId() != null) {
            LOG.trace("{} getTargetDpnForPacketOut: Viewing Subnet {}", LOGGING_PREFIX, subnetId.getValue());
            boolean match = NWUtil.isIpInSubnet(ipAddress, subOpEntry.getSubnetCidr());
            LOG.trace("{} getTargetDpnForPacketOut: Viewing Subnet {} matching {}", LOGGING_PREFIX, subnetId.getValue(), match);
            if (match) {
                return subOpEntry;
            }
        }
    }
    return null;
}
Also used : ElanTagName(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.tag.name.map.ElanTagName) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) Subnetmap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap) SubnetOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntry) NetworkMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.networkmaps.NetworkMap)

Example 15 with SubnetOpDataEntry

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntry in project netvirt by opendaylight.

the class SubnetRoutePacketInHandler method handlePacketToInternalNetwork.

private void handlePacketToInternalNetwork(byte[] dstIp, String dstIpStr, int destinationAddress, long elanTag) throws UnknownHostException {
    SubnetOpDataEntry targetSubnetForPacketOut = getTargetSubnetForPacketOut(dataBroker, elanTag, destinationAddress);
    if (targetSubnetForPacketOut == null) {
        LOG.debug("Couldn't find matching subnet for elan tag {} and destination ip {}", elanTag, dstIpStr);
        VpnManagerCounters.subnet_route_packet_failed.inc();
        return;
    }
    Optional<Subnetmap> subnetMap = VpnUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, VpnUtil.buildSubnetmapIdentifier(targetSubnetForPacketOut.getSubnetId()));
    if (!subnetMap.isPresent()) {
        LOG.debug("Couldn't find subnet map for subnet {}", targetSubnetForPacketOut.getSubnetId());
        VpnManagerCounters.subnet_route_packet_failed.inc();
        return;
    }
    String sourceIp = subnetMap.get().getRouterInterfaceFixedIp();
    if (sourceIp == null) {
        LOG.debug("Subnet map {} doesn't have a router interface ip defined", subnetMap.get().getId());
        VpnManagerCounters.subnet_route_packet_failed.inc();
        return;
    }
    String sourceMac = subnetMap.get().getRouterIntfMacAddress();
    if (sourceMac == null) {
        LOG.debug("Subnet map {} doesn't have a router interface mac address defined", subnetMap.get().getId());
        VpnManagerCounters.subnet_route_packet_failed.inc();
        return;
    }
    transmitArpPacket(targetSubnetForPacketOut.getNhDpnId(), sourceIp, sourceMac, dstIp, elanTag);
}
Also used : Subnetmap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap) SubnetOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntry)

Aggregations

SubnetOpDataEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntry)18 SubnetOpDataEntryKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntryKey)14 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)8 SubnetOpDataEntryBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntryBuilder)8 SubnetToDpn (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.subnet.op.data.entry.SubnetToDpn)7 BigInteger (java.math.BigInteger)5 Subnetmap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap)5 TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)4 SubnetToDpnKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.subnet.op.data.entry.SubnetToDpnKey)4 ArrayList (java.util.ArrayList)3 SubnetOpData (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.SubnetOpData)3 SubnetToDpnBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.subnet.op.data.entry.SubnetToDpnBuilder)3 VpnInterfaces (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.subnet.op.data.entry.subnet.to.dpn.VpnInterfaces)3 SubnetmapKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.SubnetmapKey)3 Interface (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface)2 PortOpDataEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.port.op.data.PortOpDataEntry)2 VpnInterfacesBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.subnet.op.data.entry.subnet.to.dpn.VpnInterfacesBuilder)2 VpnInterfacesKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.subnet.op.data.entry.subnet.to.dpn.VpnInterfacesKey)2 Subnetmaps (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.Subnetmaps)2 Optional (com.google.common.base.Optional)1