Search in sources :

Example 71 with Subnet

use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.Subnet in project netvirt by opendaylight.

the class NeutronPortChangeListener method handleRouterInterfaceAdded.

private void handleRouterInterfaceAdded(Port routerPort) {
    if (routerPort.getDeviceId() != null) {
        Uuid routerId = new Uuid(routerPort.getDeviceId());
        Uuid infNetworkId = routerPort.getNetworkId();
        Uuid existingVpnId = neutronvpnUtils.getVpnForNetwork(infNetworkId);
        elanService.addKnownL3DmacAddress(routerPort.getMacAddress().getValue(), infNetworkId.getValue());
        if (existingVpnId == null) {
            Set<Uuid> listVpnIds = new HashSet<>();
            Uuid vpnId = neutronvpnUtils.getVpnForRouter(routerId, true);
            if (vpnId == null) {
                vpnId = routerId;
            }
            listVpnIds.add(vpnId);
            Uuid internetVpnId = neutronvpnUtils.getInternetvpnUuidBoundToRouterId(routerId);
            List<Subnetmap> subnetMapList = new ArrayList<>();
            List<FixedIps> portIps = routerPort.getFixedIps();
            boolean portIsIpv6 = false;
            for (FixedIps portIP : portIps) {
                // and addSubnetToVpn here
                if (internetVpnId != null && portIP.getIpAddress().getIpv6Address() != null) {
                    portIsIpv6 = true;
                }
                String ipValue = String.valueOf(portIP.getIpAddress().getValue());
                Uuid subnetId = portIP.getSubnetId();
                nvpnManager.updateSubnetNodeWithFixedIp(subnetId, routerId, routerPort.getUuid(), ipValue, routerPort.getMacAddress().getValue(), vpnId);
                Subnetmap sn = neutronvpnUtils.getSubnetmap(subnetId);
                subnetMapList.add(sn);
            }
            if (portIsIpv6) {
                listVpnIds.add(internetVpnId);
                if (neutronvpnUtils.shouldVpnHandleIpVersionChoiceChangeToAdd(IpVersionChoice.IPV6, internetVpnId)) {
                    neutronvpnUtils.updateVpnInstanceWithIpFamily(internetVpnId.getValue(), IpVersionChoice.IPV6, true);
                    neutronvpnUtils.updateVpnInstanceWithFallback(internetVpnId.getValue(), true);
                }
            }
            if (!subnetMapList.isEmpty()) {
                nvpnManager.createVpnInterface(listVpnIds, routerPort, null);
            }
            for (FixedIps portIP : routerPort.getFixedIps()) {
                String ipValue = String.valueOf(portIP.getIpAddress().getValue());
                IpVersionChoice version = neutronvpnUtils.getIpVersionFromString(ipValue);
                if (neutronvpnUtils.shouldVpnHandleIpVersionChoiceChangeToAdd(version, vpnId)) {
                    neutronvpnUtils.updateVpnInstanceWithIpFamily(vpnId.getValue(), version, true);
                }
                if (version.isIpVersionChosen(IpVersionChoice.IPV4)) {
                    nvpnManager.addSubnetToVpn(vpnId, portIP.getSubnetId(), null);
                } else {
                    nvpnManager.addSubnetToVpn(vpnId, portIP.getSubnetId(), internetVpnId);
                }
                LOG.trace("NeutronPortChangeListener Add Subnet Gateway IP {} MAC {} Interface {} VPN {}", ipValue, routerPort.getMacAddress(), routerPort.getUuid().getValue(), vpnId.getValue());
            }
            nvpnManager.addToNeutronRouterInterfacesMap(routerId, routerPort.getUuid().getValue());
            nvpnNatManager.handleSubnetsForExternalRouter(routerId);
            WriteTransaction wrtConfigTxn = dataBroker.newWriteOnlyTransaction();
            String portInterfaceName = createOfPortInterface(routerPort, wrtConfigTxn);
            createElanInterface(routerPort, portInterfaceName, wrtConfigTxn);
            wrtConfigTxn.submit();
        } else {
            LOG.error("Neutron network {} corresponding to router interface port {} for neutron router {}" + " already associated to VPN {}", infNetworkId.getValue(), routerPort.getUuid().getValue(), routerId.getValue(), existingVpnId.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) ArrayList(java.util.ArrayList) 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) IpVersionChoice(org.opendaylight.netvirt.neutronvpn.api.enums.IpVersionChoice)

Example 72 with Subnet

use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.Subnet in project netvirt by opendaylight.

the class ConfigureL3VpnCommand method createL3VpnCLI.

private void createL3VpnCLI() throws InterruptedException, ExecutionException {
    if (vid == null) {
        session.getConsole().println("Please supply a valid VPN ID");
        session.getConsole().println(getHelp("create"));
        return;
    }
    if (rd == null) {
        session.getConsole().println("Please supply a valid RD");
        session.getConsole().println(getHelp("create"));
        return;
    }
    if (irt == null) {
        session.getConsole().println("Please supply a valid list of import RTs separated by {,}");
        session.getConsole().println(getHelp("create"));
        return;
    }
    if (ert == null) {
        session.getConsole().println("Please supply a valid list of export RTs separated by {,}");
        session.getConsole().println(getHelp("create"));
        return;
    }
    Uuid vuuid = new Uuid(vid);
    RpcResult<CreateL3VPNOutput> createL3VpnRpcResult = null;
    {
        ArrayList<String> rdList = new ArrayList<>(Arrays.asList(rd.split(",")));
        ArrayList<String> irtList = new ArrayList<>(Arrays.asList(irt.split(",")));
        ArrayList<String> ertList = new ArrayList<>(Arrays.asList(ert.split(",")));
        Uuid tuuid = null;
        if (tid != null) {
            tuuid = new Uuid(tid);
        }
        List<L3vpn> l3vpns = new ArrayList<>();
        L3vpn l3vpn = new L3vpnBuilder().setId(vuuid).setName(name).setRouteDistinguisher(rdList).setImportRT(irtList).setExportRT(ertList).setTenantId(tuuid).build();
        l3vpns.add(l3vpn);
        Future<RpcResult<CreateL3VPNOutput>> result = neutronvpnService.createL3VPN(new CreateL3VPNInputBuilder().setL3vpn(l3vpns).build());
        createL3VpnRpcResult = result.get();
        if (createL3VpnRpcResult.isSuccessful()) {
            session.getConsole().println("L3VPN created successfully");
            LOG.trace("createl3vpn: {}", result);
        } else {
            session.getConsole().println("Error populating createL3VPN : " + result.get().getErrors());
            session.getConsole().println(getHelp("create"));
        }
    }
    /**
     * passing a subnetId list alongwith create-l3-vpn CLI implicitly indicates that
     * association of network(s) to VPN is being intended.
     */
    if (createL3VpnRpcResult.isSuccessful()) {
        {
            List<Uuid> networkIdList = new ArrayList<>();
            if (sid != null) {
                for (String sidStr : sid.split(",")) {
                    Uuid subnetId = new Uuid(sidStr);
                    Uuid networkId = neutronVpnManager.getNetworkForSubnet(subnetId);
                    if (networkId != null) {
                        networkIdList.add(networkId);
                    } else {
                        session.getConsole().println("Could not find network for subnet " + subnetId.getValue() + ". Not proceeding with adding subnet to VPN");
                    }
                }
                if (!networkIdList.isEmpty()) {
                    Future<RpcResult<AssociateNetworksOutput>> result = neutronvpnService.associateNetworks(new AssociateNetworksInputBuilder().setVpnId(vuuid).setNetworkId(networkIdList).build());
                    RpcResult<AssociateNetworksOutput> associateNetworksRpcResult = result.get();
                    if (associateNetworksRpcResult.isSuccessful()) {
                        session.getConsole().println("Subnet(s) added to VPN successfully");
                        LOG.trace("associateNetworks: {}", result);
                    } else {
                        session.getConsole().println("Error while adding subnet(s) to VPN: " + result.get().getErrors());
                        session.getConsole().println(getHelp("create"));
                    }
                }
            }
        }
    }
}
Also used : CreateL3VPNOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.CreateL3VPNOutput) ArrayList(java.util.ArrayList) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) L3vpn(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.createl3vpn.input.L3vpn) AssociateNetworksInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.AssociateNetworksInputBuilder) Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) AssociateNetworksOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.AssociateNetworksOutput) Future(java.util.concurrent.Future) ArrayList(java.util.ArrayList) List(java.util.List) L3vpnBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.createl3vpn.input.L3vpnBuilder) CreateL3VPNInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.CreateL3VPNInputBuilder)

Example 73 with Subnet

use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.Subnet in project netvirt by opendaylight.

the class ConfigureL3VpnCommand method deleteL3VpnCLI.

private void deleteL3VpnCLI() throws InterruptedException, ExecutionException {
    if (vid == null) {
        session.getConsole().println("Please supply a valid VPN ID");
        session.getConsole().println(getHelp("delete"));
        return;
    }
    Uuid vpnId = new Uuid(vid);
    // disassociation of network(s) (removal of subnet(s)) from VPN to be followed by deletion of VPN
    RpcResult<DissociateNetworksOutput> dissociateNetworksRpcResult = null;
    List<Uuid> networkIdList = null;
    networkIdList = neutronVpnManager.getNetworksForVpn(vpnId);
    if (networkIdList != null && !networkIdList.isEmpty()) {
        Future<RpcResult<DissociateNetworksOutput>> result = neutronvpnService.dissociateNetworks(new DissociateNetworksInputBuilder().setVpnId(vpnId).setNetworkId(networkIdList).build());
        dissociateNetworksRpcResult = result.get();
        if (dissociateNetworksRpcResult.isSuccessful()) {
            session.getConsole().println("Subnet(s) removed from VPN successfully");
            LOG.trace("dissociateNetworks: {}", result);
        } else {
            session.getConsole().println("Error while removing subnet(s) from VPN: " + result.get().getErrors());
            session.getConsole().println(getHelp("delete"));
        }
    }
    if (networkIdList == null || networkIdList.isEmpty() || dissociateNetworksRpcResult.isSuccessful()) {
        List<Uuid> vpnIdList = new ArrayList<>();
        vpnIdList.add(vpnId);
        Future<RpcResult<DeleteL3VPNOutput>> result = neutronvpnService.deleteL3VPN(new DeleteL3VPNInputBuilder().setId(vpnIdList).build());
        RpcResult<DeleteL3VPNOutput> rpcResult = result.get();
        if (rpcResult.isSuccessful()) {
            session.getConsole().println("L3VPN deleted successfully");
            LOG.trace("deletel3vpn: {}", result);
        } else {
            session.getConsole().println("Error populating deleteL3VPN : " + result.get().getErrors());
            session.getConsole().println(getHelp("delete"));
        }
    } else {
        session.getConsole().println("Not proceeding with deletion of L3VPN since error(s) encountered " + "in removing subnet(s) from VPN");
    }
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) DissociateNetworksOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.DissociateNetworksOutput) DeleteL3VPNOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.DeleteL3VPNOutput) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) ArrayList(java.util.ArrayList) DeleteL3VPNInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.DeleteL3VPNInputBuilder) DissociateNetworksInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.DissociateNetworksInputBuilder)

Example 74 with Subnet

use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.Subnet in project netvirt by opendaylight.

the class NetvirtProvider method getLogicalInterfacesFromNeutronNetwork.

public List<String> getLogicalInterfacesFromNeutronNetwork(NeutronNetwork nw) {
    InstanceIdentifier<NetworkMap> networkMapIdentifier = getNetworkMapIdentifier(new Uuid(nw.getNetworkUuid()));
    NetworkMap networkMap = MDSALUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, networkMapIdentifier).orNull();
    if (networkMap == null) {
        LOG.warn("getLogicalInterfacesFromNeutronNetwork cant get NetworkMap for NW UUID [{}]", nw.getNetworkUuid());
        return Collections.emptyList();
    }
    List<String> interfaces = new ArrayList<>();
    List<Uuid> subnetUuidList = networkMap.getSubnetIdList();
    if (subnetUuidList != null) {
        for (Uuid subnetUuid : subnetUuidList) {
            InstanceIdentifier<Subnetmap> subnetId = getSubnetMapIdentifier(subnetUuid);
            Subnetmap subnet = MDSALUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, subnetId).orNull();
            if (subnet == null) {
                LOG.warn("getLogicalInterfacesFromNeutronNetwork cant get Subnetmap for NW UUID [{}] Subnet UUID " + "[{}]", nw.getNetworkUuid(), subnetUuid.getValue());
                continue;
            }
            if (subnet.getPortList() == null || subnet.getPortList().isEmpty()) {
                LOG.warn("getLogicalInterfacesFromNeutronNetwork No ports on Subnet: NW UUID [{}] Subnet UUID [{}]", nw.getNetworkUuid(), subnetUuid.getValue());
                continue;
            }
            subnet.getPortList().forEach(portId -> interfaces.add(portId.getValue()));
        }
    }
    return interfaces;
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) ArrayList(java.util.ArrayList) Subnetmap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap) NetworkMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.networkmaps.NetworkMap)

Example 75 with Subnet

use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.Subnet in project lispflowmapping by opendaylight.

the class ListenerTest method toStringTest.

/**
 * Tests {@link NetworkListener#toString}, {@link PortListener#toString}, {@link SubnetListener#toString} method.
 */
@Test
public void toStringTest() {
    final DataProcessor<Network> networkDataProcessor = Mockito.mock(DataProcessor.class);
    final DataBroker dataBroker = Mockito.mock(DataBroker.class);
    final NetworkListener networkListener = new NetworkListener(networkDataProcessor, dataBroker);
    final DataProcessor<Port> portDataProcessor = Mockito.mock(DataProcessor.class);
    final PortListener portListener = new PortListener(portDataProcessor, dataBroker);
    final DataProcessor<Subnet> subnetDataProcessor = Mockito.mock(DataProcessor.class);
    final SubnetListener subnetListener = new SubnetListener(subnetDataProcessor, dataBroker);
    assertEquals("NetworkListener", networkListener.toString());
    assertEquals("PortListener", portListener.toString());
    assertEquals("SubnetListener", subnetListener.toString());
}
Also used : Network(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.networks.rev150712.networks.attributes.networks.Network) Port(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.Port) DataBroker(org.opendaylight.controller.md.sal.binding.api.DataBroker) Subnet(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.Subnet) Test(org.junit.Test)

Aggregations

Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)72 ArrayList (java.util.ArrayList)44 BigInteger (java.math.BigInteger)30 Subnetmap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap)28 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)25 SubnetOpDataEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntry)17 Subnet (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.Subnet)15 SubnetOpDataEntryKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet.op.data.SubnetOpDataEntryKey)13 List (java.util.List)12 ExecutionException (java.util.concurrent.ExecutionException)12 TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)12 WriteTransaction (org.opendaylight.controller.md.sal.binding.api.WriteTransaction)11 FixedIps (org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes.FixedIps)11 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)10 UnknownHostException (java.net.UnknownHostException)10 Vteps (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rev160406.transport.zones.transport.zone.subnets.Vteps)10 VpnInterface (org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterface)9 ExternalSubnets (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ExternalSubnets)9 HashMap (java.util.HashMap)8 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)8