Search in sources :

Example 6 with SubnetmapBuilder

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

the class NeutronvpnManager method updateSubnetNodeWithFixedIp.

protected void updateSubnetNodeWithFixedIp(Uuid subnetId, Uuid routerId, Uuid routerInterfacePortId, String fixedIp, String routerIntfMacAddress, Uuid vpnId) {
    Subnetmap subnetmap = null;
    SubnetmapBuilder builder = null;
    InstanceIdentifier<Subnetmap> id = InstanceIdentifier.builder(Subnetmaps.class).child(Subnetmap.class, new SubnetmapKey(subnetId)).build();
    try {
        synchronized (subnetId.getValue().intern()) {
            Optional<Subnetmap> sn = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, id);
            if (sn.isPresent()) {
                builder = new SubnetmapBuilder(sn.get());
                LOG.debug("WithRouterFixedIP: Updating existing subnetmap node for subnet ID {}", subnetId.getValue());
            } else {
                LOG.error("WithRouterFixedIP: subnetmap node for subnet {} does not exist, returning ", subnetId.getValue());
                return;
            }
            builder.setRouterId(routerId);
            builder.setRouterInterfacePortId(routerInterfacePortId);
            builder.setRouterIntfMacAddress(routerIntfMacAddress);
            builder.setRouterInterfaceFixedIp(fixedIp);
            if (vpnId != null) {
                builder.setVpnId(vpnId);
            }
            subnetmap = builder.build();
            LOG.debug("WithRouterFixedIP Creating/Updating subnetMap node for Router FixedIp: {} ", subnetId.getValue());
            SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, id, subnetmap);
        }
    } catch (ReadFailedException | TransactionCommitFailedException e) {
        LOG.error("WithRouterFixedIP: subnet map for Router FixedIp failed for node {}", subnetId.getValue(), e);
    }
}
Also used : ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) SubnetmapKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.SubnetmapKey) Subnetmap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap) SubnetmapBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.SubnetmapBuilder)

Example 7 with SubnetmapBuilder

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

the class NeutronvpnManager method updateSubnetmapNodeWithPorts.

protected Subnetmap updateSubnetmapNodeWithPorts(Uuid subnetId, Uuid portId, Uuid directPortId) {
    Subnetmap subnetmap = null;
    InstanceIdentifier<Subnetmap> id = InstanceIdentifier.builder(Subnetmaps.class).child(Subnetmap.class, new SubnetmapKey(subnetId)).build();
    LOG.info("updateSubnetmapNodeWithPorts : subnetId {}, subnetMapId {}", subnetId.toString(), id.toString());
    try {
        synchronized (subnetId.getValue().intern()) {
            Optional<Subnetmap> sn = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, id);
            if (sn.isPresent()) {
                SubnetmapBuilder builder = new SubnetmapBuilder(sn.get());
                if (null != portId) {
                    List<Uuid> portList = builder.getPortList();
                    if (null == portList) {
                        portList = new ArrayList<>();
                    }
                    portList.add(portId);
                    builder.setPortList(portList);
                    LOG.debug("updateSubnetmapNodeWithPorts: Updating existing subnetmap node {} with port {}", subnetId.getValue(), portId.getValue());
                }
                if (null != directPortId) {
                    List<Uuid> directPortList = builder.getDirectPortList();
                    if (null == directPortList) {
                        directPortList = new ArrayList<>();
                    }
                    directPortList.add(directPortId);
                    builder.setDirectPortList(directPortList);
                    LOG.debug("Updating existing subnetmap node {} with port {}", subnetId.getValue(), directPortId.getValue());
                }
                subnetmap = builder.build();
                SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, id, subnetmap);
            } else {
                LOG.info("updateSubnetmapNodeWithPorts: Subnetmap node is not ready {}, put port {} in unprocessed " + "cache ", subnetId.getValue(), portId.getValue());
                unprocessedPortsMap.put(portId, subnetId);
            }
        }
    } catch (ReadFailedException | TransactionCommitFailedException e) {
        LOG.error("Updating port list of a given subnetMap failed for node: {}", subnetId.getValue(), e);
    }
    return subnetmap;
}
Also used : ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) 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) Subnetmap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap) SubnetmapBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.SubnetmapBuilder)

Example 8 with SubnetmapBuilder

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

the class NeutronvpnManager method updateSubnetNode.

protected Subnetmap updateSubnetNode(Uuid subnetId, Uuid routerId, Uuid vpnId, Uuid internetvpnId) {
    Subnetmap subnetmap = null;
    SubnetmapBuilder builder = null;
    InstanceIdentifier<Subnetmap> id = InstanceIdentifier.builder(Subnetmaps.class).child(Subnetmap.class, new SubnetmapKey(subnetId)).build();
    try {
        synchronized (subnetId.getValue().intern()) {
            Optional<Subnetmap> sn = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, id);
            if (sn.isPresent()) {
                builder = new SubnetmapBuilder(sn.get());
                LOG.debug("updating existing subnetmap node for subnet ID {}", subnetId.getValue());
            } else {
                LOG.error("subnetmap node for subnet {} does not exist, returning", subnetId.getValue());
                return null;
            }
            if (routerId != null) {
                builder.setRouterId(routerId);
            }
            if (vpnId != null) {
                builder.setVpnId(vpnId);
            }
            builder.setInternetVpnId(internetvpnId);
            subnetmap = builder.build();
            LOG.debug("Creating/Updating subnetMap node: {} ", subnetId.getValue());
            SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, id, subnetmap);
        }
    } catch (ReadFailedException | TransactionCommitFailedException e) {
        LOG.error("Subnet map update failed for node {}", subnetId.getValue(), e);
    }
    return subnetmap;
}
Also used : ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) SubnetmapKey(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.SubnetmapKey) Subnetmap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap) SubnetmapBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.SubnetmapBuilder)

Example 9 with SubnetmapBuilder

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

the class NeutronvpnManager method removePortsFromSubnetmapNode.

protected Subnetmap removePortsFromSubnetmapNode(Uuid subnetId, Uuid portId, Uuid directPortId) {
    Subnetmap subnetmap = null;
    InstanceIdentifier<Subnetmap> id = InstanceIdentifier.builder(Subnetmaps.class).child(Subnetmap.class, new SubnetmapKey(subnetId)).build();
    try {
        synchronized (subnetId.getValue().intern()) {
            Optional<Subnetmap> sn = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, id);
            if (sn.isPresent()) {
                SubnetmapBuilder builder = new SubnetmapBuilder(sn.get());
                if (null != portId && null != builder.getPortList()) {
                    List<Uuid> portList = builder.getPortList();
                    portList.remove(portId);
                    builder.setPortList(portList);
                    LOG.debug("Removing port {} from existing subnetmap node: {} ", portId.getValue(), subnetId.getValue());
                }
                if (null != directPortId && null != builder.getDirectPortList()) {
                    List<Uuid> directPortList = builder.getDirectPortList();
                    directPortList.remove(directPortId);
                    builder.setDirectPortList(directPortList);
                    LOG.debug("Removing direct port {} from existing subnetmap node: {} ", directPortId.getValue(), subnetId.getValue());
                }
                subnetmap = builder.build();
                SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, id, subnetmap);
            } else {
                LOG.info("Trying to remove port from non-existing subnetmap node {}", subnetId.getValue());
            }
        }
    } catch (ReadFailedException | TransactionCommitFailedException e) {
        LOG.error("Removing a port from port list of a subnetmap failed for node: {}", subnetId.getValue(), e);
    }
    return subnetmap;
}
Also used : ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) 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) Subnetmap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap) SubnetmapBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.SubnetmapBuilder)

Example 10 with SubnetmapBuilder

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

the class NeutronvpnManager method createSubnetmapNode.

// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
protected void createSubnetmapNode(Uuid subnetId, String subnetIp, Uuid tenantId, Uuid networkId, NetworkAttributes.NetworkType networkType, long segmentationId) {
    try {
        InstanceIdentifier<Subnetmap> subnetMapIdentifier = NeutronvpnUtils.buildSubnetMapIdentifier(subnetId);
        synchronized (subnetId.getValue().intern()) {
            LOG.info("createSubnetmapNode: subnet ID {}", subnetId.toString());
            Optional<Subnetmap> sn = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, subnetMapIdentifier);
            if (sn.isPresent()) {
                LOG.error("createSubnetmapNode: Subnetmap node for subnet ID {} already exists, returning", subnetId.getValue());
                return;
            }
            SubnetmapBuilder subnetmapBuilder = new SubnetmapBuilder().setKey(new SubnetmapKey(subnetId)).setId(subnetId).setSubnetIp(subnetIp).setTenantId(tenantId).setNetworkId(networkId).setNetworkType(networkType).setSegmentationId(segmentationId);
            LOG.debug("createSubnetmapNode: Adding a new subnet node in Subnetmaps DS for subnet {}", subnetId.getValue());
            SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, subnetMapIdentifier, subnetmapBuilder.build());
        }
    } catch (TransactionCommitFailedException | ReadFailedException e) {
        LOG.error("createSubnetmapNode: Creating subnetmap node failed for subnet {}", subnetId.getValue());
    }
    // check if there are ports to update for already created Subnetmap node
    LOG.debug("createSubnetmapNode: Update created Subnetmap for subnet {} with ports", subnetId.getValue());
    for (Map.Entry<Uuid, Uuid> entry : unprocessedPortsMap.entrySet()) {
        if (entry.getValue().getValue().equals(subnetId.getValue())) {
            updateSubnetmapNodeWithPorts(subnetId, entry.getKey(), null);
            unprocessedPortsMap.remove(entry.getKey());
        }
    }
}
Also used : TransactionCommitFailedException(org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException) ReadFailedException(org.opendaylight.controller.md.sal.common.api.data.ReadFailedException) 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) Subnetmap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap) SubnetmapBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.SubnetmapBuilder) Map(java.util.Map) VpnMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.vpnmaps.VpnMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) RouterInterfacesMap(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.RouterInterfacesMap)

Aggregations

SubnetmapBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.SubnetmapBuilder)10 SubnetmapKey (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.SubnetmapKey)8 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)7 Subnetmap (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.subnetmaps.Subnetmap)7 ReadFailedException (org.opendaylight.controller.md.sal.common.api.data.ReadFailedException)6 TransactionCommitFailedException (org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException)6 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ExecutionException (java.util.concurrent.ExecutionException)1 Mockito.doReturn (org.mockito.Mockito.doReturn)1 ReadOnlyTransaction (org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction)1 Ipv4FamilyBuilder (org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.instances.vpn.instance.Ipv4FamilyBuilder)1 InterfaceKey (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.InterfaceKey)1 AllocateIdInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdInputBuilder)1 AllocateIdOutputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.AllocateIdOutputBuilder)1 DPNTEPsInfoBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.dpn.endpoints.DPNTEPsInfoBuilder)1 DPNTEPsInfoKey (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.dpn.endpoints.DPNTEPsInfoKey)1 TunnelEndPoints (org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.op.rev160406.dpn.endpoints.dpn.teps.info.TunnelEndPoints)1