use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.NetworksKey in project netvirt by opendaylight.
the class BgpConfigurationManager method addPrefix.
public void addPrefix(String rd, String macAddress, String pfx, List<String> nhList, VrfEntry.EncapType encapType, long lbl, long l3vni, long l2vni, String gatewayMac) {
for (String nh : nhList) {
Ipv4Address nexthop = nh != null ? new Ipv4Address(nh) : null;
Long label = lbl;
InstanceIdentifier<Networks> iid = InstanceIdentifier.builder(Bgp.class).child(Networks.class, new NetworksKey(pfx, rd)).build();
NetworksBuilder networksBuilder = new NetworksBuilder().setRd(rd).setPrefixLen(pfx).setNexthop(nexthop).setLabel(label).setEthtag(BgpConstants.DEFAULT_ETH_TAG);
buildVpnEncapSpecificInfo(networksBuilder, encapType, label, l3vni, l2vni, macAddress, gatewayMac);
update(iid, networksBuilder.build());
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.NetworksKey in project netvirt by opendaylight.
the class BgpConfigurationManager method delPrefix.
public void delPrefix(String rd, String pfx) {
InstanceIdentifier.InstanceIdentifierBuilder<Networks> iib = InstanceIdentifier.builder(Bgp.class).child(Networks.class, new NetworksKey(pfx, rd));
InstanceIdentifier<Networks> iid = iib.build();
delete(iid);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.NetworksKey in project netvirt by opendaylight.
the class VpnSubnetRouteHandler method onSubnetAddedToVpn.
// TODO Clean up the exception handling
@SuppressWarnings("checkstyle:IllegalCatch")
public void onSubnetAddedToVpn(Subnetmap subnetmap, boolean isBgpVpn, Long elanTag) {
Uuid subnetId = subnetmap.getId();
String subnetIp = subnetmap.getSubnetIp();
Subnetmap subMap = null;
SubnetOpDataEntry subOpEntry = null;
SubnetOpDataEntryBuilder subOpBuilder = null;
InstanceIdentifier<SubnetOpDataEntry> subOpIdentifier = null;
Optional<SubnetOpDataEntry> optionalSubs = null;
Preconditions.checkNotNull(subnetId, LOGGING_PREFIX + " onSubnetAddedToVpn: SubnetId cannot be null or empty!");
Preconditions.checkNotNull(subnetIp, LOGGING_PREFIX + " onSubnetAddedToVpn: SubnetPrefix cannot be null or empty!");
Preconditions.checkNotNull(elanTag, LOGGING_PREFIX + " onSubnetAddedToVpn: ElanTag cannot be null or empty!");
String vpnName;
if (subnetmap.getVpnId() != null) {
vpnName = subnetmap.getVpnId().getValue();
long vpnId = VpnUtil.getVpnId(dataBroker, vpnName);
if (vpnId == VpnConstants.INVALID_ID) {
vpnOpDataSyncer.waitForVpnDataReady(VpnOpDataType.vpnInstanceToId, vpnName, VpnConstants.PER_VPN_INSTANCE_MAX_WAIT_TIME_IN_MILLISECONDS);
vpnId = VpnUtil.getVpnId(dataBroker, vpnName);
if (vpnId == VpnConstants.INVALID_ID) {
LOG.error("{} onSubnetAddedToVpn: VpnInstance to VPNId mapping not yet available for VpnName {} " + "processing subnet {} with IP {}, bailing out now.", LOGGING_PREFIX, vpnName, subnetId, subnetIp);
return;
}
}
} else {
LOG.error("onSubnetAddedToVpn: VpnId {} for subnet {} not found, bailing out", subnetmap.getVpnId(), subnetId);
return;
}
LOG.info("{} onSubnetAddedToVpn: Subnet {} with IP {} being added to vpn {}", LOGGING_PREFIX, subnetId.getValue(), subnetIp, vpnName);
// TODO(vivek): Change this to use more granularized lock at subnetId level
try {
VpnUtil.lockSubnet(lockManager, subnetId.getValue());
try {
// Please check if subnetId belongs to an External Network
InstanceIdentifier<Subnetmap> subMapid = InstanceIdentifier.builder(Subnetmaps.class).child(Subnetmap.class, new SubnetmapKey(subnetId)).build();
Optional<Subnetmap> sm = VpnUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, subMapid);
if (!sm.isPresent()) {
LOG.error("{} onSubnetAddedToVpn: Unable to retrieve subnetmap entry for subnet {} IP {}" + " vpnName {}", LOGGING_PREFIX, subnetId, subnetIp, vpnName);
return;
}
subMap = sm.get();
if (isBgpVpn) {
InstanceIdentifier<Networks> netsIdentifier = InstanceIdentifier.builder(ExternalNetworks.class).child(Networks.class, new NetworksKey(subMap.getNetworkId())).build();
Optional<Networks> optionalNets = VpnUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, netsIdentifier);
if (optionalNets.isPresent()) {
LOG.info("{} onSubnetAddedToVpn: subnet {} with IP {} is an external subnet on external " + "network {}, so ignoring this for SubnetRoute on vpn {}", LOGGING_PREFIX, subnetId.getValue(), subnetIp, subMap.getNetworkId().getValue(), vpnName);
return;
}
}
// Create and add SubnetOpDataEntry object for this subnet to the SubnetOpData container
subOpIdentifier = InstanceIdentifier.builder(SubnetOpData.class).child(SubnetOpDataEntry.class, new SubnetOpDataEntryKey(subnetId)).build();
optionalSubs = VpnUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, subOpIdentifier);
if (optionalSubs.isPresent()) {
LOG.error("{} onSubnetAddedToVpn: SubnetOpDataEntry for subnet {} with ip {} and vpn {} already" + " detected to be present", LOGGING_PREFIX, subnetId.getValue(), subnetIp, vpnName);
return;
}
LOG.debug("{} onSubnetAddedToVpn: Creating new SubnetOpDataEntry node for subnet {} subnetIp {} " + "vpn {}", LOGGING_PREFIX, subnetId.getValue(), subnetIp, vpnName);
subOpBuilder = new SubnetOpDataEntryBuilder().setKey(new SubnetOpDataEntryKey(subnetId));
subOpBuilder.setSubnetId(subnetId);
subOpBuilder.setSubnetCidr(subnetIp);
String primaryRd = VpnUtil.getPrimaryRd(dataBroker, vpnName);
if (isBgpVpn && !VpnUtil.isBgpVpn(vpnName, primaryRd)) {
LOG.error("{} onSubnetAddedToVpn: The VPN Instance name {} does not have RD. Bailing out for" + " subnet {} subnetIp {} ", LOGGING_PREFIX, vpnName, subnetId.getValue(), subnetIp);
return;
}
subOpBuilder.setVrfId(primaryRd);
subOpBuilder.setVpnName(vpnName);
subOpBuilder.setSubnetToDpn(new ArrayList<>());
subOpBuilder.setRouteAdvState(TaskState.Idle);
subOpBuilder.setElanTag(elanTag);
Long l3Vni = VpnUtil.getVpnInstanceOpData(dataBroker, primaryRd).getL3vni();
subOpBuilder.setL3vni(l3Vni);
subOpEntry = subOpBuilder.build();
MDSALUtil.syncWrite(dataBroker, LogicalDatastoreType.OPERATIONAL, subOpIdentifier, subOpEntry);
LOG.info("onSubnetAddedToVpn: Added subnetopdataentry to OP Datastore for subnet {}", subnetId.getValue());
} catch (Exception ex) {
LOG.error("Creation of SubnetOpDataEntry for subnet {} failed ", subnetId.getValue(), ex);
// The second part of this method depends on subMap being non-null so fail fast here.
return;
} finally {
VpnUtil.unlockSubnet(lockManager, subnetId.getValue());
}
// In second critical section , Port-Op-Data will be updated.
VpnUtil.lockSubnet(lockManager, subnetId.getValue());
try {
BigInteger dpnId = null;
SubnetToDpn subDpn = null;
Map<BigInteger, SubnetToDpn> subDpnMap = new HashMap<>();
optionalSubs = VpnUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, subOpIdentifier);
subOpBuilder = new SubnetOpDataEntryBuilder(optionalSubs.get()).setKey(new SubnetOpDataEntryKey(subnetId));
List<Uuid> portList = subMap.getPortList();
if (portList != null) {
for (Uuid port : portList) {
Interface intfState = InterfaceUtils.getInterfaceStateFromOperDS(dataBroker, port.getValue());
if (intfState != null) {
try {
dpnId = InterfaceUtils.getDpIdFromInterface(intfState);
} catch (Exception e) {
LOG.error("{} onSubnetAddedToVpn: Unable to obtain dpnId for interface {}," + " subnetroute inclusion for this interface for subnet {} subnetIp {} vpn {}" + " failed with exception", LOGGING_PREFIX, port.getValue(), subnetId.getValue(), subnetIp, vpnName, e);
continue;
}
if (dpnId.equals(BigInteger.ZERO)) {
LOG.error("{} onSubnetAddedToVpn: Port {} is not assigned DPN yet," + " ignoring subnet {} subnetIP {} vpn {}", LOGGING_PREFIX, port.getValue(), subnetId.getValue(), subnetIp, vpnName);
continue;
}
subOpDpnManager.addPortOpDataEntry(port.getValue(), subnetId, dpnId);
if (intfState.getOperStatus() != OperStatus.Up) {
LOG.error("{} onSubnetAddedToVpn: Port {} is not UP yet, ignoring subnet {}" + " subnetIp {} vpn {}", LOGGING_PREFIX, port.getValue(), subnetId.getValue(), subnetIp, vpnName);
continue;
}
subDpn = subOpDpnManager.addInterfaceToDpn(subnetId, dpnId, port.getValue());
if (intfState.getOperStatus() == OperStatus.Up) {
// port is UP
subDpnMap.put(dpnId, subDpn);
}
} else {
subOpDpnManager.addPortOpDataEntry(port.getValue(), subnetId, null);
}
}
if (subDpnMap.size() > 0) {
subOpBuilder.setSubnetToDpn(new ArrayList<>(subDpnMap.values()));
}
}
electNewDpnForSubnetRoute(subOpBuilder, null, /* oldDpnId */
subnetId, subMap.getNetworkId(), isBgpVpn);
subOpEntry = subOpBuilder.build();
MDSALUtil.syncUpdate(dataBroker, LogicalDatastoreType.OPERATIONAL, subOpIdentifier, subOpEntry);
LOG.info("{} onSubnetAddedToVpn: Added PortOpDataEntry and VpnInterfaces to SubnetOpData" + " for subnet {} subnetIp {} vpn {} TaskState {} lastTaskState {}", LOGGING_PREFIX, subnetId.getValue(), subnetIp, vpnName, subOpEntry.getRouteAdvState(), subOpEntry.getLastAdvState());
} catch (RuntimeException ex) {
LOG.error("{} onSubnetAddedToVpn: Creation of SubnetOpDataEntry for subnet {} subnetIp {} vpn {} failed", LOGGING_PREFIX, subnetId.getValue(), subnetIp, vpnName, ex);
} finally {
VpnUtil.unlockSubnet(lockManager, subnetId.getValue());
}
} catch (RuntimeException e) {
LOG.error("{} onSubnetAddedToVpn: Unable to handle subnet {} with ip {} added to vpn {}", LOGGING_PREFIX, subnetId.getValue(), subnetIp, vpnName, e);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.NetworksKey in project netvirt by opendaylight.
the class NeutronvpnNatManager method addExternalNetworkToRouter.
private void addExternalNetworkToRouter(Router update) {
Uuid routerId = update.getUuid();
Uuid extNetId = update.getExternalGatewayInfo().getExternalNetworkId();
List<ExternalFixedIps> externalFixedIps = update.getExternalGatewayInfo().getExternalFixedIps();
try {
Network input = neutronvpnUtils.getNeutronNetwork(extNetId);
ProviderTypes providerNwType = NeutronvpnUtils.getProviderNetworkType(input);
if (providerNwType == null) {
LOG.error("Unable to get Network Provider Type for network {}", input.getUuid().getValue());
return;
}
// Add this router to the ExtRouters list
addExternalRouter(update);
// Update External Subnets for this router
updateExternalSubnetsForRouter(routerId, extNetId, externalFixedIps);
// Create and add Networks object for this External Network to the ExternalNetworks list
InstanceIdentifier<Networks> netsIdentifier = InstanceIdentifier.builder(ExternalNetworks.class).child(Networks.class, new NetworksKey(extNetId)).build();
Optional<Networks> optionalNets = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, netsIdentifier);
if (!optionalNets.isPresent()) {
LOG.error("External Network {} not present in the NVPN datamodel", extNetId.getValue());
return;
}
NetworksBuilder builder = new NetworksBuilder(optionalNets.get());
List<Uuid> rtrList = builder.getRouterIds();
if (rtrList == null) {
rtrList = new ArrayList<>();
}
rtrList.add(routerId);
builder.setRouterIds(rtrList);
if (NeutronvpnUtils.isFlatOrVlanNetwork(input)) {
builder.setVpnid(extNetId);
}
Networks networkss = builder.build();
// Add Networks object to the ExternalNetworks list
LOG.trace("Updating externalnetworks {}", networkss);
SingleTransactionDataBroker.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, netsIdentifier, networkss);
LOG.trace("Updated externalnetworks successfully to CONFIG Datastore");
// get vpn external form this network external to setup vpnInternet for ipv6
Uuid vpnExternal = neutronvpnUtils.getVpnForNetwork(extNetId);
if (vpnExternal == null) {
LOG.debug("addExternalNetworkToRouter : no vpnExternal for Network {}", extNetId);
}
LOG.debug("addExternalNetworkToRouter : the vpnExternal {}", vpnExternal);
// get subnetmap associate to the router, any subnetmap "external" could be existing
List<Subnetmap> snList = neutronvpnUtils.getNeutronRouterSubnetMaps(routerId);
LOG.debug("addExternalNetworkToRouter : the vpnExternal {} subnetmap to be set with vpnInternet {}", vpnExternal, snList);
for (Subnetmap sn : snList) {
if (sn.getInternetVpnId() == null) {
continue;
}
IpVersionChoice ipVers = neutronvpnUtils.getIpVersionFromString(sn.getSubnetIp());
if (ipVers == IpVersionChoice.IPV6) {
LOG.debug("addExternalNetworkToRouter : setup vpnInternet IPv6 for vpnExternal {} subnetmap {}", vpnExternal, sn);
nvpnManager.updateVpnInternetForSubnet(sn, vpnExternal, true);
}
}
} catch (TransactionCommitFailedException | ReadFailedException ex) {
LOG.error("Creation of externalnetworks failed for {}", extNetId.getValue(), ex);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.networks.NetworksKey in project netvirt by opendaylight.
the class NeutronvpnNatManager method removeExternalNetwork.
public void removeExternalNetwork(Network net) {
Uuid extNetId = net.getUuid();
// Create and add Networks object for this External Network to the ExternalNetworks list
InstanceIdentifier<Networks> netsIdentifier = InstanceIdentifier.builder(ExternalNetworks.class).child(Networks.class, new NetworksKey(extNetId)).build();
try {
Optional<Networks> optionalNets = SingleTransactionDataBroker.syncReadOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, netsIdentifier);
LOG.trace("Removing Networks node {}", extNetId.getValue());
if (!optionalNets.isPresent()) {
LOG.error("External Network {} not available in the datastore", extNetId.getValue());
return;
}
// Delete Networks object from the ExternalNetworks list
LOG.trace("Deleting External Network {}", extNetId.getValue());
SingleTransactionDataBroker.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION, netsIdentifier);
LOG.trace("Deleted External Network {} successfully from CONFIG Datastore", extNetId.getValue());
} catch (TransactionCommitFailedException | ReadFailedException ex) {
LOG.error("Deletion of External Network {} failed", extNetId.getValue(), ex);
}
}
Aggregations