Search in sources :

Example 6 with FixedIpsKey

use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes.FixedIpsKey in project netvirt by opendaylight.

the class NeutronPortChangeListener method handleNeutronPortUpdated.

private void handleNeutronPortUpdated(final Port portoriginal, final Port portupdate) {
    final Map<FixedIpsKey, FixedIps> portoriginalIpsMap = portoriginal.nonnullFixedIps();
    final Map<FixedIpsKey, FixedIps> portupdateIpsMap = portupdate.nonnullFixedIps();
    if (portoriginalIpsMap == null || portoriginalIpsMap.isEmpty()) {
        handleNeutronPortCreated(portupdate);
        return;
    }
    if (portupdateIpsMap == null || portupdateIpsMap.isEmpty()) {
        LOG.info("Ignoring portUpdate (fixed_ip removal) for port {} as this case is handled " + "during subnet deletion event.", portupdate.getUuid().getValue());
        return;
    }
    if (NeutronConstants.IS_ODL_DHCP_PORT.test(portupdate)) {
        return;
    }
    jobCoordinator.enqueueJob("PORT- " + portupdate.getUuid().getValue(), () -> Collections.singletonList(txRunner.callWithNewWriteOnlyTransactionAndSubmit(CONFIGURATION, confTx -> {
        final List<Uuid> originalSnMapsIds = portoriginalIpsMap.values().stream().map(FixedIps::getSubnetId).collect(Collectors.toList());
        final List<Uuid> updateSnMapsIds = portupdateIpsMap.values().stream().map(FixedIps::getSubnetId).collect(Collectors.toList());
        Set<Uuid> originalRouterIds = new HashSet<>();
        Set<Uuid> oldVpnIds = new HashSet<>();
        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());
                }
            }
        }
        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 */
            confTx);
        }
        if (!newVpnIds.isEmpty()) {
            LOG.info("Adding VPN Interface for port {}", portupdate.getUuid().getValue());
            nvpnManager.createVpnInterface(newVpnIds, portupdate, confTx);
            if (!newRouterIds.isEmpty()) {
                for (Uuid routerId : newRouterIds) {
                    nvpnManager.addToNeutronRouterInterfacesMap(routerId, portupdate.getUuid().getValue());
                }
            }
        }
    })));
}
Also used : 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) 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 7 with FixedIpsKey

use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes.FixedIpsKey in project netvirt by opendaylight.

the class NeutronvpnManager method showNeutronPortsCLI.

/**
 * Implementation of the "vpnservice:neutron-ports-show" Karaf CLI command.
 *
 * @return a List of String to be printed on screen
 * @throws ExecutionException or InterruptedException   if there was a problem reading from the data store
 */
public List<String> showNeutronPortsCLI() throws ExecutionException, InterruptedException {
    List<String> result = new ArrayList<>();
    result.add(String.format(" %-36s  %-19s  %-13s  %-20s ", "Port ID", "Mac Address", "Prefix Length", "IP Address"));
    result.add("-------------------------------------------------------------------------------------------");
    InstanceIdentifier<Ports> portidentifier = InstanceIdentifier.create(Neutron.class).child(Ports.class);
    Optional<Ports> ports = syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, portidentifier);
    if (ports.isPresent() && ports.get().getPort() != null) {
        for (Port port : ports.get().nonnullPort().values()) {
            Map<FixedIpsKey, FixedIps> keyFixedIpsMap = port.getFixedIps();
            if (keyFixedIpsMap != null && !keyFixedIpsMap.isEmpty()) {
                List<String> ipList = new ArrayList<>();
                for (FixedIps fixedIp : keyFixedIpsMap.values()) {
                    IpAddress ipAddress = fixedIp.getIpAddress();
                    if (ipAddress.getIpv4Address() != null) {
                        ipList.add(ipAddress.getIpv4Address().getValue());
                    } else {
                        ipList.add(ipAddress.getIpv6Address().getValue());
                    }
                }
                result.add(String.format(" %-36s  %-19s  %-13s  %-20s ", port.getUuid().getValue(), port.getMacAddress().getValue(), neutronvpnUtils.getIPPrefixFromPort(port), ipList.toString()));
            } else {
                result.add(String.format(" %-36s  %-19s  %-13s  %-20s ", port.getUuid().getValue(), port.getMacAddress().getValue(), "Not Assigned", "Not Assigned"));
            }
        }
    }
    return result;
}
Also used : FixedIpsKey(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes.FixedIpsKey) VpnPortipToPort(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.neutron.vpn.portip.port.data.VpnPortipToPort) LearntVpnVipToPort(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.learnt.vpn.vip.to.port.data.LearntVpnVipToPort) Port(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.Port) ArrayList(java.util.ArrayList) Ports(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.Ports) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) FixedIps(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes.FixedIps) Neutron(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.rev150712.Neutron)

Example 8 with FixedIpsKey

use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes.FixedIpsKey in project netvirt by opendaylight.

the class NeutronvpnUtils method buildStaticMacEntry.

public static List<StaticMacEntries> buildStaticMacEntry(Port port) {
    PhysAddress physAddress = new PhysAddress(port.getMacAddress().getValue());
    Map<FixedIpsKey, FixedIps> keyFixedIpsMap = port.nonnullFixedIps();
    IpAddress ipAddress = null;
    if (isNotEmpty(keyFixedIpsMap.values())) {
        ipAddress = new ArrayList<FixedIps>(port.nonnullFixedIps().values()).get(0).getIpAddress();
    }
    StaticMacEntriesBuilder staticMacEntriesBuilder = new StaticMacEntriesBuilder();
    List<StaticMacEntries> staticMacEntries = new ArrayList<>();
    if (ipAddress != null) {
        staticMacEntries.add(staticMacEntriesBuilder.setMacAddress(physAddress).setIpPrefix(ipAddress).build());
    } else {
        staticMacEntries.add(staticMacEntriesBuilder.setMacAddress(physAddress).build());
    }
    return staticMacEntries;
}
Also used : FixedIpsKey(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes.FixedIpsKey) StaticMacEntriesBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.interfaces.elan._interface.StaticMacEntriesBuilder) ArrayList(java.util.ArrayList) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) FixedIps(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes.FixedIps) StaticMacEntries(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.elan.rev150602.elan.interfaces.elan._interface.StaticMacEntries) PhysAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.PhysAddress)

Example 9 with FixedIpsKey

use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes.FixedIpsKey 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

FixedIps (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes.FixedIps)9 FixedIpsKey (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes.FixedIpsKey)9 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)7 ArrayList (java.util.ArrayList)5 HashSet (java.util.HashSet)4 Subnetmap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap)4 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)3 Port (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.Port)3 Nullable (org.eclipse.jdt.annotation.Nullable)2 Strings (com.google.common.base.Strings)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 Gson (com.google.gson.Gson)1 JsonArray (com.google.gson.JsonArray)1 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 Duration (java.time.Duration)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Locale (java.util.Locale)1