Search in sources :

Example 6 with PortOpDataEntryKey

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

the class TunnelInterfaceStateListener method handleTunnelEventForDPNVpn.

// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
private void handleTunnelEventForDPNVpn(StateTunnelList stateTunnelList, Map<Long, String> vpnIdRdMap, TunnelAction tunnelAction, boolean isTepDeletedOnDpn, List<Uuid> subnetList, TunnelEventProcessingMethod method, VpnInterface cfgVpnInterface) {
    String rd;
    String intfName = cfgVpnInterface.getName();
    final BigInteger srcDpnId = new BigInteger(stateTunnelList.getSrcInfo().getTepDeviceId());
    String destTepIp = String.valueOf(stateTunnelList.getDstInfo().getTepIp().getValue());
    String srcTepIp = String.valueOf(stateTunnelList.getSrcInfo().getTepIp().getValue());
    int tunTypeVal = getTunnelType(stateTunnelList);
    BigInteger remoteDpnId = null;
    if (tunTypeVal == VpnConstants.ITMTunnelLocType.Internal.getValue()) {
        remoteDpnId = new BigInteger(stateTunnelList.getDstInfo().getTepDeviceId());
    }
    if (cfgVpnInterface.getVpnInstanceNames() == null) {
        LOG.warn("handleTunnelEventForDpn: no vpnName found for interface {}", intfName);
        return;
    }
    for (VpnInstanceNames vpnInstance : cfgVpnInterface.getVpnInstanceNames()) {
        String vpnName = vpnInstance.getVpnName();
        if (method == TunnelEventProcessingMethod.POPULATESUBNETS) {
            Optional<VpnInterfaceOpDataEntry> opVpnInterface = VpnUtil.getVpnInterfaceOpDataEntry(dataBroker, intfName, vpnName);
            if (opVpnInterface.isPresent() && !opVpnInterface.get().isScheduledForRemove()) {
                VpnInterfaceOpDataEntry vpnInterface = opVpnInterface.get();
                jobCoordinator.enqueueJob("VPNINTERFACE-" + intfName, new UpdateVpnInterfaceOnTunnelEvent(tunnelAction, vpnInterface, stateTunnelList, isTepDeletedOnDpn));
                // Populate the List of subnets
                InstanceIdentifier<PortOpDataEntry> portOpIdentifier = InstanceIdentifier.builder(PortOpData.class).child(PortOpDataEntry.class, new PortOpDataEntryKey(intfName)).build();
                Optional<PortOpDataEntry> optionalPortOp = VpnUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, portOpIdentifier);
                if (optionalPortOp.isPresent()) {
                    List<Uuid> subnetIdList = optionalPortOp.get().getSubnetIds();
                    if (subnetIdList != null) {
                        for (Uuid subnetId : subnetIdList) {
                            if (!subnetList.contains(subnetId)) {
                                subnetList.add(subnetId);
                            }
                        }
                    }
                }
                // Populate the map for VpnId-to-Rd
                long vpnId = VpnUtil.getVpnId(dataBroker, vpnName);
                rd = VpnUtil.getVpnRd(dataBroker, vpnName);
                vpnIdRdMap.put(vpnId, rd);
            }
        } else if (method == TunnelEventProcessingMethod.MANAGEREMOTEROUTES) {
            Optional<VpnInterfaceOpDataEntry> opVpnInterface = VpnUtil.getVpnInterfaceOpDataEntry(dataBroker, intfName, vpnName);
            if (opVpnInterface.isPresent()) {
                VpnInterfaceOpDataEntry vpnInterface = opVpnInterface.get();
                AdjacenciesOp adjacencies = vpnInterface.getAugmentation(AdjacenciesOp.class);
                List<Adjacency> adjList = adjacencies != null ? adjacencies.getAdjacency() : Collections.emptyList();
                String prefix = null;
                long vpnId = VpnUtil.getVpnId(dataBroker, vpnInterface.getVpnInstanceName());
                if (vpnIdRdMap.containsKey(vpnId)) {
                    rd = vpnIdRdMap.get(vpnId);
                    LOG.info("handleTunnelEventForDPN: Remote DpnId {} VpnId {} rd {} VpnInterface {} srcTepIp " + "{} destTepIp {}", remoteDpnId, vpnId, rd, vpnInterface, srcTepIp, destTepIp);
                    for (Adjacency adj : adjList) {
                        prefix = adj.getIpAddress();
                        long label = adj.getLabel();
                        if (tunnelAction == TunnelAction.TUNNEL_EP_ADD && tunTypeVal == VpnConstants.ITMTunnelLocType.Internal.getValue()) {
                            fibManager.manageRemoteRouteOnDPN(true, srcDpnId, vpnId, rd, prefix, destTepIp, label);
                        }
                        if (tunnelAction == TunnelAction.TUNNEL_EP_DELETE && tunTypeVal == VpnConstants.ITMTunnelLocType.Internal.getValue()) {
                            fibManager.manageRemoteRouteOnDPN(false, srcDpnId, vpnId, rd, prefix, destTepIp, label);
                        }
                    }
                }
            }
        }
    }
}
Also used : Optional(com.google.common.base.Optional) PortOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.port.op.data.PortOpDataEntry) PortOpDataEntryKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.port.op.data.PortOpDataEntryKey) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) VpnInstanceNames(org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.vpn._interface.VpnInstanceNames) AdjacenciesOp(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.AdjacenciesOp) BigInteger(java.math.BigInteger) StateTunnelList(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.tunnels_state.StateTunnelList) DcGatewayIpList(org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.DcGatewayIpList) List(java.util.List) ArrayList(java.util.ArrayList) Collectors.toList(java.util.stream.Collectors.toList) Adjacency(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.adjacency.list.Adjacency) VpnInterfaceOpDataEntry(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn._interface.op.data.VpnInterfaceOpDataEntry)

Aggregations

Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)6 PortOpDataEntryKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.port.op.data.PortOpDataEntryKey)6 PortOpDataEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.port.op.data.PortOpDataEntry)5 ArrayList (java.util.ArrayList)4 PortOpDataEntryBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.port.op.data.PortOpDataEntryBuilder)4 TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)2 SubnetOpDataEntryBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntryBuilder)2 SubnetOpDataEntryKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntryKey)2 SubnetToDpnBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.subnet.op.data.entry.SubnetToDpnBuilder)2 SubnetToDpnKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.subnet.op.data.entry.SubnetToDpnKey)2 VpnInterfaces (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.subnet.op.data.entry.subnet.to.dpn.VpnInterfaces)2 SubnetmapKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.SubnetmapKey)2 Optional (com.google.common.base.Optional)1 BigInteger (java.math.BigInteger)1 List (java.util.List)1 Collectors.toList (java.util.stream.Collectors.toList)1 Mockito.doReturn (org.mockito.Mockito.doReturn)1 Ipv4FamilyBuilder (org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.instances.vpn.instance.Ipv4FamilyBuilder)1 VpnInstanceNames (org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.vpn._interface.VpnInstanceNames)1 InterfaceKey (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceKey)1