<?xml version="1.0" encoding="UTF-8"?>
<!--
-Copyright (c) 2015 - 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
This program and the accompanying materials are made available under the
terms of the Eclipse Public License v1.0 which accompanies this distribution,
/*
- * Copyright (c) 2015 - 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
<?xml version="1.0" encoding="UTF-8"?>
-<!-- vi: set et smarttab sw=4 tabstop=4: --><!--
-Copyright (c) 2015 - 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+<!--
+Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
This program and the accompanying materials are made available under the
terms of the Eclipse Public License v1.0 which accompanies this distribution,
<?xml version="1.0" encoding="UTF-8"?>
-<!-- vi: set et smarttab sw=4 tabstop=4: -->
<!--
-Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
This program and the accompanying materials are made available under the
terms of the Eclipse Public License v1.0 which accompanies this distribution,
/*
- * Copyright (c) 2015 - 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
/*
- * Copyright (c) 2015 - 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
/*
- * Copyright (c) 2015 - 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
package org.opendaylight.vpnservice.neutronvpn;
+import com.google.common.base.Optional;
+
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.vpnservice.mdsalutil.AbstractDataChangeListener;
+import org.opendaylight.vpnservice.mdsalutil.MDSALUtil;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev140508.L2vlan;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.port.attributes.FixedIps;
import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.Ports;
import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.ports.rev150712.ports.attributes.ports.Port;
import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.rev150712.Neutron;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.neutron.port.data
+ .PortFixedipToPortNameBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.neutron.port.data
+ .PortNameToPortUuidBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.subnetmaps.Subnetmap;
import org.opendaylight.yangtools.concepts.ListenerRegistration;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.slf4j.Logger;
if (LOG.isTraceEnabled()) {
LOG.trace("Adding Port : key: " + identifier + ", value=" + input);
}
- nvpnManager.handleNeutronPortCreated(input);
+ handleNeutronPortCreated(input);
}
if (LOG.isTraceEnabled()) {
LOG.trace("Removing Port : key: " + identifier + ", value=" + input);
}
- nvpnManager.handleNeutronPortDeleted(input);
+ handleNeutronPortDeleted(input);
}
iterator.remove();
}
}
- nvpnManager.handleNeutronPortUpdated(original, update);
+ handleNeutronPortUpdated(original, update);
+ }
+ }
+
+ private void handleNeutronPortCreated(Port port) {
+ LOG.info("Of-port-interface creation");
+ int portVlanId = NeutronvpnUtils.getVlanFromNeutronPort(port);
+ // Create of-port interface for this neutron port
+ createOfPortInterface(port, portVlanId);
+ LOG.debug("Add port to subnet");
+ // add port to local Subnets DS
+ Uuid vpnId = addPortToSubnets(port);
+
+ if (vpnId != null) {
+ // create vpn-interface on this neutron port
+ LOG.debug("Adding VPN Interface");
+ nvpnManager.createVpnInterface(vpnId, port);
+ }
+ }
+
+ private void handleNeutronPortDeleted(Port port) {
+ LOG.debug("Of-port-interface removal");
+ LOG.debug("Remove port from subnet");
+ // remove port from local Subnets DS
+ Uuid vpnId = removePortFromSubnets(port);
+
+ if (vpnId != null) {
+ // remove vpn-interface for this neutron port
+ LOG.debug("removing VPN Interface");
+ nvpnManager.deleteVpnInterface(port);
+ }
+ int portVlanId = NeutronvpnUtils.getVlanFromNeutronPort(port);
+ // Remove of-port interface for this neutron port
+ deleteOfPortInterface(port, portVlanId);
+
+ }
+
+ private void handleNeutronPortUpdated(Port portoriginal, Port portupdate) {
+ LOG.debug("Add port to subnet");
+ // add port FixedIPs to local Subnets DS
+ Uuid vpnIdup = addPortToSubnets(portupdate);
+
+ if (vpnIdup != null) {
+ nvpnManager.createVpnInterface(vpnIdup, portupdate);
+ }
+
+ // remove port FixedIPs from local Subnets DS
+ Uuid vpnIdor = removePortFromSubnets(portoriginal);
+
+ if (vpnIdor != null) {
+ nvpnManager.deleteVpnInterface(portoriginal);
+ }
+ }
+
+ private void createOfPortInterface(Port port, int portVlanId) {
+ String name = NeutronvpnUtils.uuidToTapPortName(port.getUuid());
+ //String ifname = new StringBuilder(name).append(":").append(Integer.toString(portVlanId)).toString();
+ //Network network = NeutronvpnUtils.getNeutronNetwork(broker, port.getNetworkId());
+ //Boolean isVlanTransparent = network.isVlanTransparent();
+
+ LOG.debug("Creating OFPort Interface {}", name);
+ InstanceIdentifier interfaceIdentifier = NeutronvpnUtils.buildVlanInterfaceIdentifier(name);
+ try {
+ Optional<Interface> optionalInf = NeutronvpnUtils.read(broker, LogicalDatastoreType.CONFIGURATION,
+ interfaceIdentifier);
+ if (!optionalInf.isPresent()) {
+ // handle these for trunkport extensions : portVlanId, isVlanTransparent
+ Interface inf = new InterfaceBuilder().setEnabled(true).setName(name).setType(L2vlan.class).build();
+ MDSALUtil.syncWrite(broker, LogicalDatastoreType.CONFIGURATION, interfaceIdentifier, inf);
+ } else {
+ LOG.error("Interface {} is already present", name);
+ }
+ } catch (Exception e) {
+ LOG.error("failed to create interface {} due to the exception {} ", name, e.getMessage());
+ }
+
+ InstanceIdentifier portIdentifier = NeutronvpnUtils.buildPortNameToPortUuidIdentifier(name);
+ PortNameToPortUuidBuilder builder = new PortNameToPortUuidBuilder().setPortName(name).setPortId(port.getUuid());
+ MDSALUtil.syncWrite(broker, LogicalDatastoreType.CONFIGURATION, portIdentifier, builder.build());
+ LOG.debug("name-uuid map for port with name: {}, uuid: {} added to NeutronPortData DS", name, port.getUuid
+ ());
+ }
+
+ private void deleteOfPortInterface(Port port, int portVlanId) {
+ String name = NeutronvpnUtils.uuidToTapPortName(port.getUuid());
+ //String ifname = new StringBuilder(name).append(":").append(Integer.toString(portVlanId)).toString();
+ LOG.debug("Removing OFPort Interface {}", name);
+ InstanceIdentifier interfaceIdentifier = NeutronvpnUtils.buildVlanInterfaceIdentifier(name);
+ try {
+ Optional<Interface> optionalInf = NeutronvpnUtils.read(broker, LogicalDatastoreType.CONFIGURATION,
+ interfaceIdentifier);
+ if (optionalInf.isPresent()) {
+ MDSALUtil.syncDelete(broker, LogicalDatastoreType.CONFIGURATION, interfaceIdentifier);
+ } else {
+ LOG.error("Interface {} is not present", name);
+ }
+ } catch (Exception e) {
+ LOG.error("Failed to delete interface {} due to the exception {}", name, e.getMessage());
+ }
+
+ InstanceIdentifier portIdentifier = NeutronvpnUtils.buildPortNameToPortUuidIdentifier(name);
+ MDSALUtil.syncDelete(broker, LogicalDatastoreType.CONFIGURATION, portIdentifier);
+ LOG.debug("name-uuid map for port with name: {}, uuid: {} deleted from NeutronPortData DS", name, port
+ .getUuid());
+ }
+
+ // adds port to subnet list and creates vpnInterface
+ private Uuid addPortToSubnets(Port port) {
+ Uuid subnetId = null;
+ Uuid vpnId = null;
+ String name = NeutronvpnUtils.uuidToTapPortName(port.getUuid());
+
+ // find all subnets to which this port is associated
+ List<FixedIps> ips = port.getFixedIps();
+ for (FixedIps ip : ips) {
+ String ipValue = ip.getIpAddress().getIpv4Address().getValue();
+
+ InstanceIdentifier id = NeutronvpnUtils.buildFixedIpToPortNameIdentifier(ipValue);
+ PortFixedipToPortNameBuilder builder = new PortFixedipToPortNameBuilder().setPortFixedip(ipValue)
+ .setPortName(name);
+ MDSALUtil.syncWrite(broker, LogicalDatastoreType.CONFIGURATION, id, builder.build());
+ LOG.debug("fixedIp-name map for neutron port with fixedIp: {}, name: {} added to NeutronPortData DS",
+ ipValue, name);
+
+ subnetId = ip.getSubnetId();
+ Subnetmap subnetmap = nvpnManager.updateSubnetNode(subnetId, null, null, null, null, port.getUuid());
+ if (vpnId == null && subnetmap != null) {
+ vpnId = subnetmap.getVpnId();
+ }
+ }
+ return vpnId;
+ }
+
+ private Uuid removePortFromSubnets(Port port) {
+ Uuid subnetId = null;
+ Uuid vpnId = null;
+
+ // find all Subnets to which this port is associated
+ List<FixedIps> ips = port.getFixedIps();
+ for (FixedIps ip : ips) {
+ String ipValue = ip.getIpAddress().getIpv4Address().getValue();
+
+ InstanceIdentifier id = NeutronvpnUtils.buildFixedIpToPortNameIdentifier(ipValue);
+ MDSALUtil.syncDelete(broker, LogicalDatastoreType.CONFIGURATION, id);
+ LOG.debug("fixedIp-name map for neutron port with fixedIp: {} deleted from NeutronPortData DS", ipValue);
+
+ subnetId = ip.getSubnetId();
+ Subnetmap subnetmap = nvpnManager.removeFromSubnetNode(subnetId, null, null, null, port.getUuid());
+ if (vpnId == null && subnetmap != null) {
+ vpnId = subnetmap.getVpnId();
+ }
}
+ return vpnId;
}
}
/*
- * Copyright (c) 2015 - 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
/*
- * Copyright (c) 2015 - 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
*/
package org.opendaylight.vpnservice.neutronvpn;
+import com.google.common.base.Optional;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.vpnservice.mdsalutil.AbstractDataChangeListener;
+import org.opendaylight.vpnservice.mdsalutil.MDSALUtil;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.rev150712.Neutron;
import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.Subnets;
import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.Subnet;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.networkmaps.NetworkMap;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.networkmaps.NetworkMapBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.networkmaps.NetworkMapKey;
import org.opendaylight.yangtools.concepts.ListenerRegistration;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.util.ArrayList;
+import java.util.List;
+
public class NeutronSubnetChangeListener extends AbstractDataChangeListener<Subnet> implements AutoCloseable {
private static final Logger LOG = LoggerFactory.getLogger(NeutronSubnetChangeListener.class);
if (LOG.isTraceEnabled()) {
LOG.trace("Adding Subnet : key: " + identifier + ", value=" + input);
}
- nvpnManager.handleNeutronSubnetCreated(input.getUuid(), input.getNetworkId(), input.getTenantId());
+ handleNeutronSubnetCreated(input.getUuid(), input.getNetworkId(), input.getTenantId());
}
@Override
if (LOG.isTraceEnabled()) {
LOG.trace("Removing subnet : key: " + identifier + ", value=" + input);
}
- nvpnManager.handleNeutronSubnetDeleted(input.getUuid(), input.getNetworkId(), null);
+ handleNeutronSubnetDeleted(input.getUuid(), input.getNetworkId(), null);
}
@Override
LOG.trace("Updating Subnet : key: " + identifier + ", original value=" + original + ", update value=" +
update);
}
- nvpnManager.handleNeutronSubnetUpdated(update.getUuid(), update.getNetworkId(), update.getTenantId());
+ handleNeutronSubnetUpdated(update.getUuid(), update.getNetworkId(), update.getTenantId());
+ }
+
+ private void handleNeutronSubnetCreated(Uuid subnetId, Uuid networkId, Uuid tenantId) {
+ nvpnManager.updateSubnetNode(subnetId, tenantId, networkId, null, null, null);
+ if (networkId != null && NeutronvpnUtils.getNeutronNetwork(broker, networkId) != null) {
+ createSubnetToNetworkMapping(subnetId, networkId);
+ }
+ }
+
+ private void handleNeutronSubnetDeleted(Uuid subnetId, Uuid networkId, Uuid tenantId) {
+ Uuid vpnId = NeutronvpnUtils.getVpnForNetwork(broker, networkId);
+ if (vpnId != null) {
+ nvpnManager.removeSubnetFromVpn(vpnId, subnetId);
+ }
+ if (networkId != null) {
+ deleteSubnetToNetworkMapping(subnetId, networkId);
+ }
+ }
+
+ private void handleNeutronSubnetUpdated(Uuid subnetId, Uuid networkId, Uuid tenantId) {
+ Uuid oldNetworkId = NeutronvpnUtils.getSubnetmap(broker, subnetId).getNetworkId();
+ if (oldNetworkId != null && !oldNetworkId.equals(networkId)) {
+ deleteSubnetToNetworkMapping(subnetId, oldNetworkId);
+ }
+ if (networkId != null && !networkId.equals(oldNetworkId)) {
+ createSubnetToNetworkMapping(subnetId, networkId);
+ }
+ nvpnManager.updateSubnetNode(subnetId, tenantId, networkId, null, null, null);
+ }
+
+ private void createSubnetToNetworkMapping(Uuid subnetId, Uuid networkId) {
+ try {
+ InstanceIdentifier networkMapIdentifier = NeutronvpnUtils.buildNetworkMapIdentifier(networkId);
+ Optional<NetworkMap> optionalNetworkMap = NeutronvpnUtils.read(broker, LogicalDatastoreType.CONFIGURATION,
+ networkMapIdentifier);
+ NetworkMapBuilder nwMapBuilder = null;
+ if (optionalNetworkMap.isPresent()) {
+ nwMapBuilder = new NetworkMapBuilder(optionalNetworkMap.get());
+ } else {
+ nwMapBuilder = new NetworkMapBuilder().setKey(new NetworkMapKey(networkId)).setNetworkId(networkId);
+ LOG.debug("Adding a new network node in NetworkMaps DS for network {}", networkId.getValue());
+ }
+ List<Uuid> subnetIdList = nwMapBuilder.getSubnetIdList();
+ if (subnetIdList == null) {
+ subnetIdList = new ArrayList<>();
+ }
+ subnetIdList.add(subnetId);
+ nwMapBuilder.setSubnetIdList(subnetIdList);
+ MDSALUtil.syncWrite(broker, LogicalDatastoreType.CONFIGURATION, networkMapIdentifier, nwMapBuilder.build());
+ LOG.debug("Created subnet-network mapping for subnet {} network {}", subnetId.getValue(),
+ networkId.getValue());
+ } catch (Exception e) {
+ LOG.error("Create subnet-network mapping failed for subnet {} network {}", subnetId.getValue(),
+ networkId.getValue());
+ }
+ }
+
+ private void deleteSubnetToNetworkMapping(Uuid subnetId, Uuid networkId) {
+ try {
+ InstanceIdentifier networkMapIdentifier = NeutronvpnUtils.buildNetworkMapIdentifier(networkId);
+ Optional<NetworkMap> optionalNetworkMap = NeutronvpnUtils.read(broker, LogicalDatastoreType.CONFIGURATION,
+ networkMapIdentifier);
+ if (optionalNetworkMap.isPresent()) {
+ NetworkMapBuilder nwMapBuilder = new NetworkMapBuilder(optionalNetworkMap.get());
+ List<Uuid> subnetIdList = nwMapBuilder.getSubnetIdList();
+ if (subnetIdList.remove(subnetId)) {
+ if (subnetIdList.size() == 0) {
+ MDSALUtil.syncDelete(broker, LogicalDatastoreType.CONFIGURATION, networkMapIdentifier);
+ LOG.debug("Deleted network node in NetworkMaps DS for network {}", subnetId.getValue(),
+ networkId.getValue());
+ } else {
+ nwMapBuilder.setSubnetIdList(subnetIdList);
+ MDSALUtil.syncWrite(broker, LogicalDatastoreType.CONFIGURATION, networkMapIdentifier,
+ nwMapBuilder.build());
+ LOG.debug("Deleted subnet-network mapping for subnet {} network {}", subnetId.getValue(),
+ networkId.getValue());
+ }
+ } else {
+ LOG.error("Subnet {} is not mapped to network {}", subnetId.getValue(), networkId.getValue());
+ }
+ } else {
+ LOG.error("network {} not present for subnet {} ", networkId, subnetId);
+ }
+ } catch (Exception e) {
+ LOG.error("Delete subnet-network mapping failed for subnet {} network {}", subnetId.getValue(),
+ networkId.getValue());
+ }
}
}
/*
- * Copyright (c) 2015 - 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
import com.google.common.util.concurrent.SettableFuture;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.vpnservice.mdsalutil.MDSALUtil;
import org.opendaylight.vpnservice.mdsalutil.interfaces.IMdsalApiManager;
import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterface;
import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterfaceBuilder;
import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterfaceKey;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev140508.L2vlan;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceBuilder;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid;
import org.opendaylight.yang.gen.v1.urn.opendaylight.l3vpn.rev130911.Adjacencies;
import org.opendaylight.yang.gen.v1.urn.opendaylight.l3vpn.rev130911.AdjacenciesBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.getl3vpn.output.L3vpnInstances;
import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.getl3vpn.output
.L3vpnInstancesBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.networkmaps.NetworkMap;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.networkmaps.NetworkMapBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.networkmaps.NetworkMapKey;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.neutron.port.data
- .PortFixedipToPortNameBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.neutron.port.data
- .PortNameToPortUuidBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.subnetmaps.Subnetmap;
import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.subnetmaps.SubnetmapBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.subnetmaps.SubnetmapKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.vpnmaps.VpnMap;
import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.vpnmaps.VpnMapBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.vpnmaps.VpnMapKey;
-import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.common.RpcError;
import org.opendaylight.yangtools.yang.common.RpcError.ErrorType;
InstanceIdentifier<Subnetmap> id = InstanceIdentifier.builder(Subnetmaps.class).
child(Subnetmap.class, new SubnetmapKey(subnetId)).build();
- Optional<Subnetmap> sn = read(LogicalDatastoreType.CONFIGURATION, id);
+ Optional<Subnetmap> sn = NeutronvpnUtils.read(broker, LogicalDatastoreType.CONFIGURATION, id);
logger.debug("updating Subnet :read: ");
if (sn.isPresent()) {
builder = new SubnetmapBuilder(sn.get());
try {
InstanceIdentifier<Subnetmap> id = InstanceIdentifier.builder(Subnetmaps.class).
child(Subnetmap.class, new SubnetmapKey(subnetId)).build();
- Optional<Subnetmap> sn = read(LogicalDatastoreType.CONFIGURATION, id);
+ Optional<Subnetmap> sn = NeutronvpnUtils.read(broker, LogicalDatastoreType.CONFIGURATION, id);
if (sn.isPresent()) {
SubnetmapBuilder builder = new SubnetmapBuilder(sn.get());
return subnetmap;
}
- private void createSubnetToNetworkMapping(Uuid subnetId, Uuid networkId) {
- try {
- InstanceIdentifier networkMapIdentifier = NeutronvpnUtils.buildNetworkMapIdentifier(networkId);
- Optional<NetworkMap> optionalNetworkMap = read(LogicalDatastoreType.CONFIGURATION, networkMapIdentifier);
- NetworkMapBuilder nwMapBuilder = null;
- if (optionalNetworkMap.isPresent()) {
- nwMapBuilder = new NetworkMapBuilder(optionalNetworkMap.get());
- } else {
- nwMapBuilder = new NetworkMapBuilder().setKey(new NetworkMapKey(networkId)).setNetworkId(networkId);
- logger.debug("Adding a new network node in NetworkMaps DS for network {}", networkId.getValue());
- }
- List<Uuid> subnetIdList = nwMapBuilder.getSubnetIdList();
- if (subnetIdList == null) {
- subnetIdList = new ArrayList<>();
- }
- subnetIdList.add(subnetId);
- nwMapBuilder.setSubnetIdList(subnetIdList);
- MDSALUtil.syncWrite(broker, LogicalDatastoreType.CONFIGURATION, networkMapIdentifier, nwMapBuilder.build());
- logger.debug("Created subnet-network mapping for subnet {} network {}", subnetId.getValue(),
- networkId.getValue());
- } catch (Exception e) {
- logger.error("Create subnet-network mapping failed for subnet {} network {}", subnetId.getValue(),
- networkId.getValue());
- }
- }
-
- private void deleteSubnetToNetworkMapping(Uuid subnetId, Uuid networkId) {
- try {
- InstanceIdentifier networkMapIdentifier = NeutronvpnUtils.buildNetworkMapIdentifier(networkId);
- Optional<NetworkMap> optionalNetworkMap = read(LogicalDatastoreType.CONFIGURATION, networkMapIdentifier);
- if (optionalNetworkMap.isPresent()) {
- NetworkMapBuilder nwMapBuilder = new NetworkMapBuilder(optionalNetworkMap.get());
- List<Uuid> subnetIdList = nwMapBuilder.getSubnetIdList();
- if (subnetIdList.remove(subnetId)) {
- if (subnetIdList.size() == 0) {
- MDSALUtil.syncDelete(broker, LogicalDatastoreType.CONFIGURATION, networkMapIdentifier);
- logger.debug("Deleted network node in NetworkMaps DS for network {}", subnetId.getValue(),
- networkId.getValue());
- } else {
- nwMapBuilder.setSubnetIdList(subnetIdList);
- MDSALUtil.syncWrite(broker, LogicalDatastoreType.CONFIGURATION, networkMapIdentifier,
- nwMapBuilder.build());
- logger.debug("Deleted subnet-network mapping for subnet {} network {}", subnetId.getValue(),
- networkId.getValue());
- }
- } else {
- logger.error("Subnet {} is not mapped to network {}", subnetId.getValue(), networkId.getValue());
- }
- } else {
- logger.error("network {} not present for subnet {} ", networkId, subnetId);
- }
- } catch (Exception e) {
- logger.error("Delete subnet-network mapping failed for subnet {} network {}", subnetId.getValue(),
- networkId.getValue());
- }
- }
-
private void updateVpnInstanceNode(String name, List<String> rd, List<String> irt, List<String> ert) {
try {
List<VpnTarget> vpnTargetList = new ArrayList<VpnTarget>();
InstanceIdentifier<VpnInstance> vpnIdentifier = InstanceIdentifier.builder(VpnInstances.class).
child(VpnInstance.class, new VpnInstanceKey(name)).build();
- Optional<VpnInstance> optionalVpn = read(LogicalDatastoreType.CONFIGURATION, vpnIdentifier);
+ Optional<VpnInstance> optionalVpn = NeutronvpnUtils.read(broker, LogicalDatastoreType.CONFIGURATION,
+ vpnIdentifier);
logger.debug("Creating/Updating a new vpn-instance node: {} ", name);
if (optionalVpn.isPresent()) {
builder = new VpnInstanceBuilder(optionalVpn.get());
VpnMapBuilder builder;
InstanceIdentifier<VpnMap> vpnMapIdentifier = InstanceIdentifier.builder(VpnMaps.class)
.child(VpnMap.class, new VpnMapKey(vpnId)).build();
- Optional<VpnMap> optionalVpnMap = read(LogicalDatastoreType.CONFIGURATION, vpnMapIdentifier);
+ Optional<VpnMap> optionalVpnMap = NeutronvpnUtils.read(broker, LogicalDatastoreType.CONFIGURATION,
+ vpnMapIdentifier);
if (optionalVpnMap.isPresent()) {
builder = new VpnMapBuilder(optionalVpnMap.get());
} else {
private void clearFromVpnMaps(Uuid id, Uuid router, List<Uuid> networks) {
InstanceIdentifier<VpnMap> vpnMapIdentifier = InstanceIdentifier.builder(VpnMaps.class)
.child(VpnMap.class, new VpnMapKey(id)).build();
- Optional<VpnMap> optionalVpnMap = read(LogicalDatastoreType.CONFIGURATION, vpnMapIdentifier);
+ Optional<VpnMap> optionalVpnMap = NeutronvpnUtils.read(broker, LogicalDatastoreType.CONFIGURATION,
+ vpnMapIdentifier);
if (optionalVpnMap.isPresent()) {
VpnMap vpnMap = optionalVpnMap.get();
VpnMapBuilder vpnMapBuilder = new VpnMapBuilder(vpnMap);
logger.debug("VPNMaps DS clear success for VPN {} ", id.getValue());
}
- private void createOfPortInterface(Port port, int portVlanId) {
- String name = NeutronvpnUtils.uuidToTapPortName(port.getUuid());
- //String ifname = new StringBuilder(name).append(":").append(Integer.toString(portVlanId)).toString();
- //Network network = NeutronvpnUtils.getNeutronNetwork(broker, port.getNetworkId());
- //Boolean isVlanTransparent = network.isVlanTransparent();
-
- logger.debug("Creating OFPort Interface {}", name);
- InstanceIdentifier interfaceIdentifier = NeutronvpnUtils.buildVlanInterfaceIdentifier(name);
- try {
- Optional<Interface> optionalInf = read(LogicalDatastoreType.CONFIGURATION, interfaceIdentifier);
- if (!optionalInf.isPresent()) {
- // handle these for trunkport extensions : portVlanId, isVlanTransparent
- Interface inf = new InterfaceBuilder().setEnabled(true).setName(name).setType(L2vlan.class).build();
- MDSALUtil.syncWrite(broker, LogicalDatastoreType.CONFIGURATION, interfaceIdentifier, inf);
- } else {
- logger.error("Interface {} is already present", name);
- }
- } catch (Exception e) {
- logger.error("failed to create interface {} due to the exception {} ", name, e.getMessage());
- }
-
- InstanceIdentifier portIdentifier = NeutronvpnUtils.buildPortNameToPortUuidIdentifier(name);
- PortNameToPortUuidBuilder builder = new PortNameToPortUuidBuilder().setPortName(name).setPortId(port.getUuid());
- MDSALUtil.syncWrite(broker, LogicalDatastoreType.CONFIGURATION, portIdentifier, builder.build());
- logger.debug("name-uuid map for port with name: {}, uuid: {} added to NeutronPortData DS", name, port.getUuid
- ());
- }
-
- private void deleteOfPortInterface(Port port, int portVlanId) {
- String name = NeutronvpnUtils.uuidToTapPortName(port.getUuid());
- //String ifname = new StringBuilder(name).append(":").append(Integer.toString(portVlanId)).toString();
- logger.debug("Removing OFPort Interface {}", name);
- InstanceIdentifier interfaceIdentifier = NeutronvpnUtils.buildVlanInterfaceIdentifier(name);
- try {
- Optional<Interface> optionalInf = read(LogicalDatastoreType.CONFIGURATION, interfaceIdentifier);
- if (optionalInf.isPresent()) {
- MDSALUtil.syncDelete(broker, LogicalDatastoreType.CONFIGURATION, interfaceIdentifier);
- } else {
- logger.error("Interface {} is not present", name);
- }
- } catch (Exception e) {
- logger.error("Failed to delete interface {} due to the exception {}", name, e.getMessage());
- }
-
- InstanceIdentifier portIdentifier = NeutronvpnUtils.buildPortNameToPortUuidIdentifier(name);
- MDSALUtil.syncDelete(broker, LogicalDatastoreType.CONFIGURATION, portIdentifier);
- logger.debug("name-uuid map for port with name: {}, uuid: {} deleted from NeutronPortData DS", name, port
- .getUuid());
- }
-
private void deleteVpnInstance(Uuid vpnId) {
InstanceIdentifier<VpnInstance> vpnIdentifier = InstanceIdentifier.builder(VpnInstances.class).
}
- private void createVpnInterface(Uuid vpnId, Port port) {
+ protected void createVpnInterface(Uuid vpnId, Port port) {
if (vpnId == null || port == null) {
return;
}
}
- private void deleteVpnInterface(Port port) {
+ protected void deleteVpnInterface(Port port) {
if (port != null) {
String pname = NeutronvpnUtils.uuidToTapPortName(port.getUuid());
}
}
- // adds port to subnet list and creates vpnInterface
- private Uuid addPortToSubnets(Port port) {
- Uuid subnetId = null;
- Uuid vpnId = null;
- String name = NeutronvpnUtils.uuidToTapPortName(port.getUuid());
-
- // find all subnets to which this port is associated
- List<FixedIps> ips = port.getFixedIps();
- for (FixedIps ip : ips) {
- String ipValue = ip.getIpAddress().getIpv4Address().getValue();
-
- InstanceIdentifier id = NeutronvpnUtils.buildFixedIpToPortNameIdentifier(ipValue);
- PortFixedipToPortNameBuilder builder = new PortFixedipToPortNameBuilder().setPortFixedip(ipValue)
- .setPortName(name);
- MDSALUtil.syncWrite(broker, LogicalDatastoreType.CONFIGURATION, id, builder.build());
- logger.debug("fixedIp-name map for neutron port with fixedIp: {}, name: {} added to NeutronPortData DS",
- ipValue, name);
-
- subnetId = ip.getSubnetId();
- Subnetmap subnetmap = updateSubnetNode(subnetId, null, null, null, null, port.getUuid());
- if (vpnId == null && subnetmap != null) {
- vpnId = subnetmap.getVpnId();
- }
- }
- return vpnId;
- }
-
- private Uuid removePortFromSubnets(Port port) {
- Uuid subnetId = null;
- Uuid vpnId = null;
-
- // find all Subnets to which this port is associated
- List<FixedIps> ips = port.getFixedIps();
- for (FixedIps ip : ips) {
- String ipValue = ip.getIpAddress().getIpv4Address().getValue();
-
- InstanceIdentifier id = NeutronvpnUtils.buildFixedIpToPortNameIdentifier(ipValue);
- MDSALUtil.syncDelete(broker, LogicalDatastoreType.CONFIGURATION, id);
- logger.debug("fixedIp-name map for neutron port with fixedIp: {} deleted from NeutronPortData DS",
- ipValue);
-
- subnetId = ip.getSubnetId();
- Subnetmap subnetmap = removeFromSubnetNode(subnetId, null, null, null, port.getUuid());
- if (vpnId == null && subnetmap != null) {
- vpnId = subnetmap.getVpnId();
- }
- }
- return vpnId;
- }
-
- protected void handleNeutronSubnetCreated(Uuid subnetId, Uuid networkId, Uuid tenantId) {
- updateSubnetNode(subnetId, tenantId, networkId, null, null, null);
- if (networkId != null && NeutronvpnUtils.getNeutronNetwork(broker, networkId) != null) {
- createSubnetToNetworkMapping(subnetId, networkId);
- }
- }
-
- protected void handleNeutronSubnetDeleted(Uuid subnetId, Uuid networkId, Uuid tenantId) {
- Uuid vpnId = NeutronvpnUtils.getVpnForNetwork(broker, networkId);
- if (vpnId != null) {
- removeSubnetFromVpn(vpnId, subnetId);
- }
- if (networkId != null) {
- deleteSubnetToNetworkMapping(subnetId, networkId);
- }
- }
-
- protected void handleNeutronSubnetUpdated(Uuid subnetId, Uuid networkId, Uuid tenantId) {
- Uuid oldNetworkId = NeutronvpnUtils.getSubnetmap(broker, subnetId).getNetworkId();
- if (oldNetworkId != null && !oldNetworkId.equals(networkId)) {
- deleteSubnetToNetworkMapping(subnetId, oldNetworkId);
- }
- if (networkId != null && !networkId.equals(oldNetworkId)) {
- createSubnetToNetworkMapping(subnetId, networkId);
- }
- updateSubnetNode(subnetId, tenantId, networkId, null, null, null);
- }
-
- protected void handleNeutronPortCreated(Port port) {
- logger.info("Of-port-interface creation");
- int portVlanId = NeutronvpnUtils.getVlanFromNeutronPort(port);
- // Create of-port interface for this neutron port
- createOfPortInterface(port, portVlanId);
- logger.debug("Add port to subnet");
- // add port to local Subnets DS
- Uuid vpnId = addPortToSubnets(port);
-
- if (vpnId != null) {
- // create vpn-interface on this neutron port
- logger.debug("Adding VPN Interface");
- createVpnInterface(vpnId, port);
- }
- }
-
- protected void handleNeutronPortDeleted(Port port) {
- logger.debug("Of-port-interface removal");
- logger.debug("Remove port from subnet");
- // remove port from local Subnets DS
- Uuid vpnId = removePortFromSubnets(port);
-
- if (vpnId != null) {
- // remove vpn-interface for this neutron port
- logger.debug("removing VPN Interface");
- deleteVpnInterface(port);
- }
- int portVlanId = NeutronvpnUtils.getVlanFromNeutronPort(port);
- // Remove of-port interface for this neutron port
- deleteOfPortInterface(port, portVlanId);
-
- }
-
- protected void handleNeutronPortUpdated(Port portoriginal, Port portupdate) {
- logger.debug("Add port to subnet");
- // add port FixedIPs to local Subnets DS
- Uuid vpnIdup = addPortToSubnets(portupdate);
-
- if (vpnIdup != null) {
- createVpnInterface(vpnIdup, portupdate);
- }
-
- // remove port FixedIPs from local Subnets DS
- Uuid vpnIdor = removePortFromSubnets(portoriginal);
-
- if (vpnIdor != null) {
- deleteVpnInterface(portoriginal);
- }
- }
-
public void createL3Vpn(Uuid vpn, String name, Uuid tenant, List<String> rd, List<String> irt, List<String> ert,
Uuid router, List<Uuid> networks) {
// get all vpns
InstanceIdentifier<VpnInstances> vpnsIdentifier =
InstanceIdentifier.builder(VpnInstances.class).build();
- Optional<VpnInstances> optionalVpns = read(LogicalDatastoreType.CONFIGURATION, vpnsIdentifier);
+ Optional<VpnInstances> optionalVpns = NeutronvpnUtils.read(broker, LogicalDatastoreType.CONFIGURATION,
+ vpnsIdentifier);
if (optionalVpns.isPresent()) {
for (VpnInstance vpn : optionalVpns.get().getVpnInstance()) {
vpns.add(vpn);
InstanceIdentifier.builder(VpnInstances.class)
.child(VpnInstance.class, new VpnInstanceKey(name)).build();
// read VpnInstance Info
- Optional<VpnInstance> optionalVpn = read(LogicalDatastoreType.CONFIGURATION, vpnIdentifier);
+ Optional<VpnInstance> optionalVpn = NeutronvpnUtils.read(broker, LogicalDatastoreType.CONFIGURATION,
+ vpnIdentifier);
if (optionalVpn.isPresent()) {
vpns.add(optionalVpn.get());
} else {
}
l3vpn.setId(vpnId).setRouteDistinguisher(rd).setImportRT(irtList).setExportRT(ertList);
- Optional<VpnMap> optionalVpnMap =
- read(LogicalDatastoreType.CONFIGURATION, vpnMapIdentifier);
+ Optional<VpnMap> optionalVpnMap = NeutronvpnUtils.read(broker, LogicalDatastoreType.CONFIGURATION,
+ vpnMapIdentifier);
if (optionalVpnMap.isPresent()) {
VpnMap vpnMap = optionalVpnMap.get();
l3vpn.setRouterId(vpnMap.getRouterId()).setNetworkIds(vpnMap.getNetworkIds())
InstanceIdentifier<VpnInstance> vpnIdentifier =
InstanceIdentifier.builder(VpnInstances.class)
.child(VpnInstance.class, new VpnInstanceKey(vpn.getValue())).build();
- Optional<VpnInstance> optionalVpn = read(LogicalDatastoreType.CONFIGURATION, vpnIdentifier);
+ Optional<VpnInstance> optionalVpn = NeutronvpnUtils.read(broker, LogicalDatastoreType.CONFIGURATION,
+ vpnIdentifier);
if (optionalVpn.isPresent()) {
removeL3Vpn(vpn);
} else {
}
InstanceIdentifier<VpnInterface> vpnIfIdentifier = InstanceIdentifier.builder(VpnInterfaces.class).
child(VpnInterface.class, new VpnInterfaceKey(ifname)).build();
- Optional<VpnInterface> optionalVpnInterface = read(LogicalDatastoreType.CONFIGURATION,
- vpnIfIdentifier);
+ Optional<VpnInterface> optionalVpnInterface = NeutronvpnUtils.read(broker, LogicalDatastoreType
+ .CONFIGURATION, vpnIfIdentifier);
if (optionalVpnInterface.isPresent()) {
Adjacencies erAdjs = new AdjacenciesBuilder().setAdjacency(Arrays.asList(erAdj)).build();
VpnInterface vpnIf = new VpnInterfaceBuilder().setKey(new VpnInterfaceKey(ifname))
return result;
}
- private <T extends DataObject> Optional<T> read(LogicalDatastoreType datastoreType, InstanceIdentifier<T> path) {
-
- ReadOnlyTransaction tx = broker.newReadOnlyTransaction();
-
- Optional<T> result = Optional.absent();
- try {
- result = tx.read(datastoreType, path).get();
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
-
- return result;
- }
-
protected Subnet getNeutronSubnet(Uuid subnetId) {
InstanceIdentifier<Subnet> inst = InstanceIdentifier.create(Neutron.class).
child(Subnets.class).child(Subnet.class, new SubnetKey(subnetId));
- Optional<Subnet> sn = read(LogicalDatastoreType.CONFIGURATION, inst);
+ Optional<Subnet> sn = NeutronvpnUtils.read(broker, LogicalDatastoreType.CONFIGURATION, inst);
if (sn.isPresent()) {
return sn.get();
if (portId != null) {
InstanceIdentifier<Port> pid = InstanceIdentifier.create(Neutron.class).
child(Ports.class).child(Port.class, new PortKey(portId));
- Optional<Port> optPort = read(LogicalDatastoreType.CONFIGURATION, pid);
+ Optional<Port> optPort = NeutronvpnUtils.read(broker, LogicalDatastoreType.CONFIGURATION, pid);
if (optPort.isPresent()) {
return optPort.get();
}
protected Port getNeutronPort(Uuid portId) {
InstanceIdentifier<Port> pid = InstanceIdentifier.create(Neutron.class).
child(Ports.class).child(Port.class, new PortKey(portId));
- Optional<Port> optPort = read(LogicalDatastoreType.CONFIGURATION, pid);
+ Optional<Port> optPort = NeutronvpnUtils.read(broker, LogicalDatastoreType.CONFIGURATION, pid);
if (optPort.isPresent()) {
return optPort.get();
}
List<Uuid> subnets = new ArrayList<Uuid>();
//read subnetmaps
InstanceIdentifier<Subnetmaps> subnetmapsid = InstanceIdentifier.builder(Subnetmaps.class).build();
- Optional<Subnetmaps> subnetmaps = read(LogicalDatastoreType.CONFIGURATION, subnetmapsid);
+ Optional<Subnetmaps> subnetmaps = NeutronvpnUtils.read(broker, LogicalDatastoreType.CONFIGURATION,
+ subnetmapsid);
if (subnetmaps.isPresent()) {
Subnetmaps smaps = subnetmaps.get();
List<Subnetmap> subnetMapList = smaps.getSubnetmap();
result.add("---------------------------------------------------------------------------------------");
InstanceIdentifier<Ports> portidentifier = InstanceIdentifier.create(Neutron.class).child(Ports.class);
try {
- Optional<Ports> ports = read(LogicalDatastoreType.CONFIGURATION, portidentifier);
+ Optional<Ports> ports = NeutronvpnUtils.read(broker, LogicalDatastoreType.CONFIGURATION, portidentifier);
if (ports.isPresent()) {
List<Port> portList = ports.get().getPort();
for (Port port : portList) {
result.add(String.format(" %-22s %-22s %-22s %-6s ", NeutronvpnUtils.uuidToTapPortName(port
.getUuid()), port.getMacAddress(), port.getFixedIps().get(0).getIpAddress().getIpv4Address()
- .getValue(), getIPPrefixFromPort(port)));
+ .getValue(), NeutronvpnUtils.getIPPrefixFromPort(broker, port)));
}
}
} catch (Exception e) {
return result;
}
- private Short getIPPrefixFromPort(Port port) {
- Short prefix = new Short((short) 0);
- String cidr = "";
- try {
- Uuid subnetUUID = port.getFixedIps().get(0).getSubnetId();
-
- org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets
- .SubnetKey subnetkey = new org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets
- .rev150712.subnets.attributes.subnets.SubnetKey(subnetUUID);
- InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets
- .attributes.subnets.Subnet> subnetidentifier = InstanceIdentifier.create(Neutron.class).child(org
- .opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.Subnets
- .class).child(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets
- .attributes.subnets.Subnet.class, subnetkey);
- Optional<org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes
- .subnets.Subnet> subnet = read(LogicalDatastoreType.CONFIGURATION, subnetidentifier);
-
- if (subnet.isPresent()) {
- cidr = subnet.get().getCidr();
- // Extract the prefix length from cidr
- String[] parts = cidr.split("/");
- if ((parts.length == 2)) {
- prefix = Short.valueOf(parts[1]);
- return prefix;
- } else {
- logger.trace("Could not retrieve prefix from subnet CIDR");
- System.out.println("Could not retrieve prefix from subnet CIDR");
- }
- } else {
- logger.trace("Unable to read on subnet datastore");
- }
- } catch (Exception e) {
- logger.trace("Failed to retrieve IP prefix from port : ", e);
- System.out.println("Failed to retrieve IP prefix from port : " + e.getMessage());
- }
- return null;
- }
-
public List<String> showVpnConfigCLI(Uuid vpnuuid) {
List<String> result = new ArrayList<String>();
if (vpnuuid == null) {
/*
- * Copyright (c) 2015 - 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
/*
- * Copyright (c) 2015 - 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.VpnMaps;
import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.networkmaps.NetworkMap;
import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.networkmaps.NetworkMapKey;
-
import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.neutron.port.data
.PortFixedipToPortName;
import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.neutronvpn.rev150602.neutron.port.data
}
protected static VpnMap getVpnMap(DataBroker broker, Uuid id) {
- InstanceIdentifier<VpnMap> vpnMapIdentifier = InstanceIdentifier.builder(VpnMaps.class)
- .child(VpnMap.class, new VpnMapKey(id)).build();
- Optional<VpnMap> optionalVpnMap = read(broker, LogicalDatastoreType.CONFIGURATION,
- vpnMapIdentifier);
+ InstanceIdentifier<VpnMap> vpnMapIdentifier = InstanceIdentifier.builder(VpnMaps.class).child(VpnMap.class,
+ new VpnMapKey(id)).build();
+ Optional<VpnMap> optionalVpnMap = read(broker, LogicalDatastoreType.CONFIGURATION, vpnMapIdentifier);
if (optionalVpnMap.isPresent()) {
return optionalVpnMap.get();
}
protected static Uuid getVpnForNetwork(DataBroker broker, Uuid network) {
InstanceIdentifier<VpnMaps> vpnMapsIdentifier = InstanceIdentifier.builder(VpnMaps.class).build();
- Optional<VpnMaps> optionalVpnMaps = read(broker, LogicalDatastoreType.CONFIGURATION,
- vpnMapsIdentifier);
+ Optional<VpnMaps> optionalVpnMaps = read(broker, LogicalDatastoreType.CONFIGURATION, vpnMapsIdentifier);
if (optionalVpnMaps.isPresent()) {
VpnMaps vpnMaps = optionalVpnMaps.get();
List<VpnMap> allMaps = vpnMaps.getVpnMap();
protected static Uuid getVpnForRouter(DataBroker broker, Uuid router) {
InstanceIdentifier<VpnMaps> vpnMapsIdentifier = InstanceIdentifier.builder(VpnMaps.class).build();
- Optional<VpnMaps> optionalVpnMaps = read(broker, LogicalDatastoreType.CONFIGURATION,
- vpnMapsIdentifier);
+ Optional<VpnMaps> optionalVpnMaps = read(broker, LogicalDatastoreType.CONFIGURATION, vpnMapsIdentifier);
if (optionalVpnMaps.isPresent()) {
VpnMaps vpnNets = optionalVpnMaps.get();
List<VpnMap> allMaps = vpnNets.getVpnMap();
protected static Uuid getRouterforVpn(DataBroker broker, Uuid vpnId) {
InstanceIdentifier<VpnMap> vpnMapIdentifier = InstanceIdentifier.builder(VpnMaps.class)
.child(VpnMap.class, new VpnMapKey(vpnId)).build();
- Optional<VpnMap> optionalVpnMap = read(broker, LogicalDatastoreType.CONFIGURATION,
- vpnMapIdentifier);
+ Optional<VpnMap> optionalVpnMap = read(broker, LogicalDatastoreType.CONFIGURATION, vpnMapIdentifier);
if (optionalVpnMap.isPresent()) {
VpnMap vpnMap = optionalVpnMap.get();
return vpnMap.getRouterId();
protected static List<Uuid> getSubnetIdsFromNetworkId(DataBroker broker, Uuid networkId) {
InstanceIdentifier id = buildNetworkMapIdentifier(networkId);
- Optional<NetworkMap> optionalNetworkMap = read(broker, LogicalDatastoreType.CONFIGURATION,
- id);
+ Optional<NetworkMap> optionalNetworkMap = read(broker, LogicalDatastoreType.CONFIGURATION, id);
if (optionalNetworkMap.isPresent()) {
return optionalNetworkMap.get().getSubnetIdList();
}
protected static Router getNeutronRouter(DataBroker broker, Uuid routerId) {
- InstanceIdentifier<Router> inst = InstanceIdentifier.create(Neutron.class).
- child(Routers.class).child(Router.class, new RouterKey(routerId));
-
+ InstanceIdentifier<Router> inst = InstanceIdentifier.create(Neutron.class).child(Routers.class).child(Router
+ .class, new RouterKey(routerId));
Optional<Router> rtr = read(broker, LogicalDatastoreType.CONFIGURATION, inst);
if (rtr.isPresent()) {
return rtr.get();
protected static Network getNeutronNetwork(DataBroker broker, Uuid networkId) {
logger.debug("getNeutronNetwork for {}", networkId.getValue());
- InstanceIdentifier<Network> inst = InstanceIdentifier.create(Neutron.class).
- child(Networks.class).child(Network.class, new NetworkKey(networkId));
-
+ InstanceIdentifier<Network> inst = InstanceIdentifier.create(Neutron.class).child(Networks.class).child
+ (Network.class, new NetworkKey(networkId));
Optional<Network> net = read(broker, LogicalDatastoreType.CONFIGURATION, inst);
if (net.isPresent()) {
return net.get();
}
}
+ protected static Short getIPPrefixFromPort(DataBroker broker, Port port) {
+ Short prefix = new Short((short) 0);
+ String cidr = "";
+ try {
+ Uuid subnetUUID = port.getFixedIps().get(0).getSubnetId();
+
+ org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets
+ .SubnetKey subnetkey = new org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets
+ .rev150712.subnets.attributes.subnets.SubnetKey(subnetUUID);
+ InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets
+ .attributes.subnets.Subnet> subnetidentifier = InstanceIdentifier.create(Neutron.class).child(org
+ .opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.Subnets
+ .class).child(org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets
+ .attributes.subnets.Subnet.class, subnetkey);
+ Optional<org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes
+ .subnets.Subnet> subnet = read(broker, LogicalDatastoreType.CONFIGURATION, subnetidentifier);
+
+ if (subnet.isPresent()) {
+ cidr = subnet.get().getCidr();
+ // Extract the prefix length from cidr
+ String[] parts = cidr.split("/");
+ if ((parts.length == 2)) {
+ prefix = Short.valueOf(parts[1]);
+ return prefix;
+ } else {
+ logger.trace("Could not retrieve prefix from subnet CIDR");
+ System.out.println("Could not retrieve prefix from subnet CIDR");
+ }
+ } else {
+ logger.trace("Unable to read on subnet datastore");
+ }
+ } catch (Exception e) {
+ logger.trace("Failed to retrieve IP prefix from port : ", e);
+ System.out.println("Failed to retrieve IP prefix from port : " + e.getMessage());
+ }
+ return null;
+ }
+
static InstanceIdentifier<PortNameToPortUuid> buildPortNameToPortUuidIdentifier(String portname) {
InstanceIdentifier<PortNameToPortUuid> id = InstanceIdentifier.builder(NeutronPortData.class).child
(PortNameToPortUuid.class, new PortNameToPortUuidKey(portname)).build();
/*
- * Copyright (c) 2015-2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
*
* Generated from: yang module name: neutronvpn-impl yang module local name: neutronvpn-impl
* Generated by: org.opendaylight.controller.config.yangjmxgenerator.plugin.JMXGenerator
-* Generated at: Thu Jan 06 10:51:12 IST 2015
+* Generated at: Thu Jan 06 10:51:12 IST 2016
*
* Do not modify this file unless it is present under src/main directory
*/
<?xml version="1.0" encoding="UTF-8"?>
-<!-- vi: set et smarttab sw=4 tabstop=4: --><!--
-Copyright (c) 2015 - 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+<!--
+Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
This program and the accompanying materials are made available under the
terms of the Eclipse Public License v1.0 which accompanies this distribution,
/*
- * Copyright (c) 2015 - 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
/*
- * Copyright (c) 2015 - 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
/*
- * Copyright (c) 2015 - 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+ * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
-<!-- * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+
+This program and the accompanying materials are made available under the
+terms of the Eclipse Public License v1.0 which accompanies this distribution,
+and is available at http://www.eclipse.org/legal/epl-v10.html
-->
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
<?xml version="1.0" encoding="UTF-8"?>
<!--
-Copyright (c) 2015 - 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
+
This program and the accompanying materials are made available under the
terms of the Eclipse Public License v1.0 which accompanies this distribution,
-and is available at http://www.eclipse.org/legal/epl-v10.html INTERNAL
+and is available at http://www.eclipse.org/legal/epl-v10.html
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">