Search in sources :

Example 61 with Subnetmap

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap in project netvirt by opendaylight.

the class NeutronPortChangeListener method handleNeutronPortUpdated.

private void handleNeutronPortUpdated(final Port portoriginal, final Port portupdate) {
    final List<FixedIps> portoriginalIps = portoriginal.getFixedIps();
    final List<FixedIps> portupdateIps = portupdate.getFixedIps();
    if (portoriginalIps == null || portoriginalIps.isEmpty()) {
        handleNeutronPortCreated(portupdate);
        return;
    }
    if (portupdateIps == null || portupdateIps.isEmpty()) {
        LOG.info("Ignoring portUpdate (fixed_ip removal) for port {} as this case is handled " + "during subnet deletion event.", portupdate.getUuid().getValue());
        return;
    }
    jobCoordinator.enqueueJob("PORT- " + portupdate.getUuid().getValue(), () -> Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(tx -> {
        final List<Uuid> originalSnMapsIds = portoriginalIps.stream().map(FixedIps::getSubnetId).collect(Collectors.toList());
        final List<Uuid> updateSnMapsIds = portupdateIps.stream().map(FixedIps::getSubnetId).collect(Collectors.toList());
        Set<Uuid> originalRouterIds = new HashSet<>();
        Set<Uuid> oldVpnIds = new HashSet<Uuid>();
        Uuid oldRouterId = null;
        for (Uuid snId : originalSnMapsIds) {
            if (!updateSnMapsIds.remove(snId)) {
                // snId was present in originalSnMapsIds, but not in updateSnMapsIds
                Subnetmap subnetMapOld = nvpnManager.removePortsFromSubnetmapNode(snId, portoriginal.getUuid(), null);
                if (subnetMapOld != null && subnetMapOld.getVpnId() != null) {
                    oldVpnIds.add(subnetMapOld.getVpnId());
                }
                if (subnetMapOld != null && subnetMapOld.getInternetVpnId() != null) {
                    oldVpnIds.add(subnetMapOld.getInternetVpnId());
                }
                if (subnetMapOld != null && subnetMapOld.getRouterId() != null) {
                    originalRouterIds.add(subnetMapOld.getRouterId());
                }
            }
        }
        Set<Uuid> newVpnIds = new HashSet();
        Set<Uuid> newRouterIds = new HashSet<>();
        for (Uuid snId : updateSnMapsIds) {
            Subnetmap subnetMapNew = nvpnManager.updateSubnetmapNodeWithPorts(snId, portupdate.getUuid(), null);
            if (subnetMapNew != null) {
                if (subnetMapNew.getVpnId() != null) {
                    newVpnIds.add(subnetMapNew.getVpnId());
                }
                if (subnetMapNew.getInternetVpnId() != null) {
                    newVpnIds.add(subnetMapNew.getInternetVpnId());
                }
                if (subnetMapNew.getRouterId() != null) {
                    newRouterIds.add(subnetMapNew.getRouterId());
                }
            }
        }
        WriteTransaction wrtConfigTxn = dataBroker.newWriteOnlyTransaction();
        if (!oldVpnIds.isEmpty()) {
            LOG.info("removing VPN Interface for port {}", portoriginal.getUuid().getValue());
            if (!originalRouterIds.isEmpty()) {
                for (Uuid routerId : originalRouterIds) {
                    nvpnManager.removeFromNeutronRouterInterfacesMap(routerId, portoriginal.getUuid().getValue());
                }
            }
            nvpnManager.deleteVpnInterface(portoriginal.getUuid().getValue(), null, /* vpn-id */
            wrtConfigTxn);
        }
        if (!newVpnIds.isEmpty()) {
            LOG.info("Adding VPN Interface for port {}", portupdate.getUuid().getValue());
            nvpnManager.createVpnInterface(newVpnIds, portupdate, wrtConfigTxn);
            if (!newRouterIds.isEmpty()) {
                for (Uuid routerId : newRouterIds) {
                    nvpnManager.addToNeutronRouterInterfacesMap(routerId, portupdate.getUuid().getValue());
                }
            }
        }
    })));
}
Also used : WriteTransaction(org.opendaylight.controller.md.sal.binding.api.WriteTransaction) 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) FixedIps(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes.FixedIps) HashSet(java.util.HashSet)

Example 62 with Subnetmap

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap in project netvirt by opendaylight.

the class NeutronPortChangeListener method handleRouterGatewayUpdated.

private void handleRouterGatewayUpdated(Port routerGwPort) {
    Uuid routerId = new Uuid(routerGwPort.getDeviceId());
    Uuid networkId = routerGwPort.getNetworkId();
    Network network = neutronvpnUtils.getNeutronNetwork(networkId);
    if (network == null) {
        return;
    }
    boolean isExternal = neutronvpnUtils.getIsExternal(network);
    if (isExternal) {
        Uuid vpnInternetId = neutronvpnUtils.getVpnForNetwork(networkId);
        if (vpnInternetId != null) {
            List<Subnetmap> snList = neutronvpnUtils.getNeutronRouterSubnetMaps(routerId);
            for (Subnetmap sn : snList) {
                if (sn.getNetworkId() == networkId) {
                    continue;
                }
                if (neutronvpnUtils.getIpVersionFromString(sn.getSubnetIp()) != IpVersionChoice.IPV6) {
                    continue;
                }
                nvpnManager.addSubnetToVpn(null, sn.getId(), vpnInternetId);
            }
        }
    }
    elanService.addKnownL3DmacAddress(routerGwPort.getMacAddress().getValue(), networkId.getValue());
    Router router = neutronvpnUtils.getNeutronRouter(routerId);
    if (router == null) {
        LOG.warn("No router found for router GW port {} for router {}", routerGwPort.getUuid().getValue(), routerId.getValue());
        return;
    }
    gwMacResolver.sendArpRequestsToExtGateways(router);
    setExternalGwMac(routerGwPort, routerId);
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) Network(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.networks.Network) Subnetmap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap) Router(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.Router)

Example 63 with Subnetmap

use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap in project netvirt by opendaylight.

the class ShowSubnet method doExecute.

@Override
@SuppressWarnings("checkstyle:RegexpSinglelineJava")
protected Object doExecute() throws Exception {
    if (subnetmap == null && subnetopdata == null && (options == null || options.isEmpty())) {
        getSubnet();
        System.out.println("Following subnetId is present in both subnetMap and subnetOpDataEntry\n");
        for (Subnetmap candidateSubnetmap : subnetmapList) {
            SubnetOpDataEntry data = subnetOpDataEntryMap.get(candidateSubnetmap.getId());
            if (data != null) {
                System.out.println(candidateSubnetmap.getId().toString() + "\n");
            }
        }
        System.out.println("\n\nFollowing subnetId is present in subnetMap but not in subnetOpDataEntry\n");
        for (Subnetmap candidateSubnetmap : subnetmapList) {
            SubnetOpDataEntry data = subnetOpDataEntryMap.get(candidateSubnetmap.getId());
            if (data == null) {
                System.out.println(candidateSubnetmap.getId().toString() + "\n");
            }
        }
        getshowVpnCLIHelp();
    } else if (subnetmap == null) {
        InstanceIdentifier<SubnetOpDataEntry> subOpIdentifier = InstanceIdentifier.builder(SubnetOpData.class).child(SubnetOpDataEntry.class, new SubnetOpDataEntryKey(new Uuid(subnetopdata))).build();
        Optional<SubnetOpDataEntry> optionalSubs = syncReadOptional(dataBroker, OPERATIONAL, subOpIdentifier);
        SubnetOpDataEntry data = optionalSubs.get();
        System.out.println("Fetching subnetmap for given subnetId\n");
        System.out.println("------------------------------------------------------------------------------");
        System.out.println("Key: " + data.getKey() + "\n" + "VrfId: " + data.getVrfId() + "\n" + "ElanTag: " + "" + data.getElanTag() + "\n" + "NhDpnId: " + data.getNhDpnId() + "\n" + "RouteAdvState: " + data.getRouteAdvState() + "\n" + "SubnetCidr: " + data.getSubnetCidr() + "\n" + "SubnetToDpnList: " + data.getSubnetToDpn() + "\n" + "VpnName: " + data.getVpnName() + "\n");
        System.out.println("------------------------------------------------------------------------------");
    }
    if (subnetmap == null && subnetopdata != null) {
        InstanceIdentifier<SubnetOpDataEntry> subOpIdentifier = InstanceIdentifier.builder(SubnetOpData.class).child(SubnetOpDataEntry.class).build();
        Optional<SubnetOpDataEntry> optionalSubnetOpDataEntries = syncReadOptional(dataBroker, OPERATIONAL, subOpIdentifier);
        if (optionalSubnetOpDataEntries.isPresent()) {
            optionalSubnetOpDataEntries.asSet().forEach(subnetOpDataEntry -> {
                SubnetOpDataEntry data = subnetOpDataEntry;
                System.out.println("Fetching subnetmapdataentry for given subnetId\n");
                System.out.println("------------------------" + "------------------------------------------------------");
                System.out.println("Key: " + data.getKey() + "\n" + "VrfId: " + data.getVrfId() + "\n" + "ElanTag: " + "" + data.getElanTag() + "\n" + "NhDpnId: " + data.getNhDpnId() + "\n" + "RouteAdvState: " + data.getRouteAdvState() + "\n" + "SubnetCidr: " + data.getSubnetCidr() + "\n" + "SubnetToDpnList: " + data.getSubnetToDpn() + "\n" + "VpnName: " + data.getVpnName() + "\n");
                System.out.println("------------------------" + "------------------------------------------------------");
            });
        }
    }
    if (subnetmap != null && subnetopdata == null) {
        InstanceIdentifier<Subnetmap> id = InstanceIdentifier.builder(Subnetmaps.class).child(Subnetmap.class, new SubnetmapKey(new Uuid(subnetmap))).build();
        Optional<Subnetmap> sn = syncReadOptional(dataBroker, CONFIGURATION, id);
        Subnetmap data = sn.get();
        System.out.println("Fetching subnetopdata for given subnetId\n");
        System.out.println("------------------------------------------------------------------------------");
        String getRouterInterfacePortId = (data.getRouterInterfacePortId() != null ? data.getRouterInterfacePortId().getValue() : "null");
        System.out.println("Key: " + data.getKey() + "\n" + "VpnId: " + data.getVpnId() + "\n" + "InternetVpnId: " + data.getInternetVpnId() + "\n" + "DirectPortList: " + data.getDirectPortList() + "\n" + "NetworkId: " + data.getNetworkId() + "\n" + "Network-type: " + data.getNetworkType() + "\n" + "Network-segmentation-Id: " + data.getSegmentationId() + "\n" + "PortList: " + data.getPortList() + "\n" + "RouterInterfaceFixedIp: " + data.getRouterInterfaceFixedIp() + "\n" + "RouterInterfacePortId: " + getRouterInterfacePortId + "\n" + "RouterIntfMacAddress: " + data.getRouterIntfMacAddress() + "\n" + "SubnetIp: " + data.getSubnetIp() + "\n" + "TenantId: " + data.getTenantId() + "\n");
        System.out.println("------------------------------------------------------------------------------");
    } else if (subnetopdata == null) {
        InstanceIdentifier<Subnetmap> id = InstanceIdentifier.builder(Subnetmaps.class).child(Subnetmap.class, new SubnetmapKey(new Uuid(subnetmap))).build();
        Optional<Subnetmap> sn = syncReadOptional(dataBroker, CONFIGURATION, id);
        Subnetmap data = sn.get();
        System.out.println("Fetching subnetopdata for given subnetId\n");
        System.out.println("------------------------------------------------------------------------------");
        String getRouterInterfacePortId = (data.getRouterInterfacePortId() != null ? data.getRouterInterfacePortId().getValue() : "null");
        System.out.println("Key: " + data.getKey() + "\n" + "VpnId: " + data.getVpnId() + "\n" + "InternetVpnId: " + data.getInternetVpnId() + "\n" + "DirectPortList: " + data.getDirectPortList() + "\n" + "NetworkId: " + data.getNetworkId() + "\n" + "Network-type: " + data.getNetworkType() + "\n" + "Network-segmentation-Id: " + data.getSegmentationId() + "\n" + "PortList: " + data.getPortList() + "\n" + "RouterInterfaceFixedIp: " + data.getRouterInterfaceFixedIp() + "\n" + "RouterInterfacePortId: " + getRouterInterfacePortId + "\n" + "RouterIntfMacAddress: " + data.getRouterIntfMacAddress() + "\n" + "SubnetIp: " + data.getSubnetIp() + "\n" + "TenantId: " + data.getTenantId() + "\n");
        System.out.println("------------------------------------------------------------------------------");
    } else {
        InstanceIdentifier<SubnetOpDataEntry> subOpIdentifier = InstanceIdentifier.builder(SubnetOpData.class).child(SubnetOpDataEntry.class, new SubnetOpDataEntryKey(new Uuid(subnetopdata))).build();
        Optional<SubnetOpDataEntry> optionalSubs = syncReadOptional(dataBroker, OPERATIONAL, subOpIdentifier);
        SubnetOpDataEntry data = optionalSubs.get();
        System.out.println("Fetching subnetmap for given subnetId\n");
        System.out.println("------------------------------------------------------------------------------");
        System.out.println("Key: " + data.getKey() + "\n" + "VrfId: " + data.getVrfId() + "\n" + "ElanTag: " + "" + data.getElanTag() + "\n" + "NhDpnId: " + data.getNhDpnId() + "\n" + "RouteAdvState: " + data.getRouteAdvState() + "\n" + "SubnetCidr: " + data.getSubnetCidr() + "\n" + "SubnetToDpnList: " + data.getSubnetToDpn() + "\n" + "VpnName: " + data.getVpnName() + "\n");
        System.out.println("------------------------------------------------------------------------------");
    }
    Boolean optionsSubnetopdataall = false;
    Boolean optionsSubnetmapall = false;
    if (options != null && !options.isEmpty()) {
        for (String opt : options) {
            String optLowCase = opt == null ? "" : opt.toLowerCase(Locale.ENGLISH);
            if (optLowCase.startsWith("subnetop")) {
                optionsSubnetopdataall = true;
            }
            if (optLowCase.startsWith("subnetmap")) {
                optionsSubnetmapall = true;
            }
        }
    }
    if (optionsSubnetopdataall) {
        InstanceIdentifier<SubnetOpData> subOpIdentifier = InstanceIdentifier.builder(SubnetOpData.class).build();
        Optional<SubnetOpData> optionalSubnetOpData = syncReadOptional(dataBroker, OPERATIONAL, subOpIdentifier);
        if (optionalSubnetOpData.isPresent()) {
            List<SubnetOpDataEntry> subnetOpDataEntryList = optionalSubnetOpData.get().getSubnetOpDataEntry();
            System.out.println("number of subnetOpDataEntry found are : " + subnetOpDataEntryList + "\n");
            subnetOpDataEntryList.forEach(subnetOpDataEntry -> {
                SubnetOpDataEntry data = subnetOpDataEntry;
                System.out.println("Fetching subnetmap for given subnetId\n");
                System.out.println("------------------------" + "------------------------------------------------------");
                System.out.println("Key: " + data.getKey() + "\n" + "VrfId: " + data.getVrfId() + "\n" + "ElanTag: " + "" + data.getElanTag() + "\n" + "NhDpnId: " + data.getNhDpnId() + "\n" + "RouteAdvState: " + data.getRouteAdvState() + "\n" + "SubnetCidr: " + data.getSubnetCidr() + "\n" + "SubnetToDpnList: " + data.getSubnetToDpn() + "\n" + "VpnName: " + data.getVpnName() + "\n");
                System.out.println("------------------------" + "------------------------------------------------------");
            });
        } else {
            System.out.println("No SubnetOpDataEntry present in Oper DS");
        }
    }
    if (optionsSubnetmapall) {
        InstanceIdentifier<Subnetmaps> subMapIdentifier = InstanceIdentifier.builder(Subnetmaps.class).build();
        Optional<Subnetmaps> optionalSubnetmaps = syncReadOptional(dataBroker, CONFIGURATION, subMapIdentifier);
        if (optionalSubnetmaps.isPresent()) {
            List<Subnetmap> subnetMapList = optionalSubnetmaps.get().getSubnetmap();
            System.out.println("number of subnetmaps found are : " + subnetMapList.size() + "\n");
            subnetMapList.forEach(sn -> {
                if (sn != null) {
                    System.out.println("Fetching subnetmap for given subnetId\n");
                    System.out.println("------------------------" + "------------------------------------------------------");
                    System.out.println("Uuid: " + sn.getId() + "\n" + "SubnetIp: " + sn.getSubnetIp() + "\n" + "NetworkId: " + sn.getNetworkId() + "\n" + "NetworkType: " + sn.getNetworkType() + "\nSegmentationId: " + sn.getSegmentationId() + "\n" + "TenantId: " + sn.getTenantId() + "\n" + "RouterId: " + sn.getRouterId() + "\n" + "RouterInterfacePortId: " + sn.getRouterInterfacePortId() + "\nRouterIntfMacAddress: " + sn.getRouterIntfMacAddress() + "\n" + "RouterInterfaceFixedIp: " + sn.getRouterInterfaceFixedIp() + "\n" + "VpnId: " + sn.getVpnId() + "\n" + "InternetVpnId: " + sn.getInternetVpnId() + "\n");
                    if (sn.getPortList() != null) {
                        System.out.println("There are " + sn.getPortList().size() + " port in the port-list");
                        for (int i = 0; i < sn.getPortList().size(); i++) {
                            System.out.println("\tport num " + i + " :\t" + sn.getPortList().get(i));
                        }
                    }
                    if (sn.getDirectPortList() != null) {
                        System.out.println("There are " + sn.getDirectPortList().size() + " port in the list of direct-port");
                        for (int i = 0; i < sn.getDirectPortList().size(); i++) {
                            System.out.println("\tdirect port num " + i + " :\t" + sn.getDirectPortList().get(i));
                        }
                    }
                    System.out.println("------------------------" + "------------------------------------------------------");
                }
            });
        } else {
            System.out.println("No Subnetmap present in Config DS");
        }
    }
    getshowVpnCLIHelp();
    return null;
}
Also used : Optional(com.google.common.base.Optional) SingleTransactionDataBroker.syncReadOptional(org.opendaylight.genius.datastoreutils.SingleTransactionDataBroker.syncReadOptional) 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) SubnetOpData(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.SubnetOpData) Subnetmaps(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.Subnetmaps) SubnetOpDataEntryKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntryKey) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) SubnetmapKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.SubnetmapKey) InstanceIdentifier(org.opendaylight.yangtools.yang.binding.InstanceIdentifier)

Aggregations

Subnetmap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap)50 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)47 ArrayList (java.util.ArrayList)20 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)15 SubnetmapKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.SubnetmapKey)12 TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)11 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)10 IpVersionChoice (org.opendaylight.netvirt.neutronvpn.api.enums.IpVersionChoice)9 Network (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.networks.Network)9 SubnetOpDataEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntry)8 HashSet (java.util.HashSet)7 SubnetOpDataEntryKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntryKey)7 Subnetmaps (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.Subnetmaps)7 SubnetmapBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.SubnetmapBuilder)7 FixedIps (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes.FixedIps)7 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)5 SubnetOpDataEntryBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntryBuilder)5 Router (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.l3.rev150712.routers.attributes.routers.Router)5 BigInteger (java.math.BigInteger)4 HashMap (java.util.HashMap)4