use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.of.object.Of in project netvirt by opendaylight.
the class SubnetOpDpnManager method removeInterfaceFromDpn.
public boolean removeInterfaceFromDpn(Uuid subnetId, BigInteger dpnId, String intfName) {
boolean dpnRemoved = false;
try {
InstanceIdentifier<SubnetOpDataEntry> subOpIdentifier = InstanceIdentifier.builder(SubnetOpData.class).child(SubnetOpDataEntry.class, new SubnetOpDataEntryKey(subnetId)).build();
InstanceIdentifier<SubnetToDpn> dpnOpId = subOpIdentifier.child(SubnetToDpn.class, new SubnetToDpnKey(dpnId));
Optional<SubnetToDpn> optionalSubDpn = VpnUtil.read(broker, LogicalDatastoreType.OPERATIONAL, dpnOpId);
if (!optionalSubDpn.isPresent()) {
LOG.debug("removeInterfaceFromDpn: Cannot delete, SubnetToDpn for intf {} subnet {} DPN {}" + " not available in datastore", intfName, subnetId.getValue(), dpnId);
return false;
}
SubnetToDpnBuilder subDpnBuilder = new SubnetToDpnBuilder(optionalSubDpn.get());
List<VpnInterfaces> vpnIntfList = subDpnBuilder.getVpnInterfaces();
VpnInterfaces vpnIntfs = new VpnInterfacesBuilder().setKey(new VpnInterfacesKey(intfName)).setInterfaceName(intfName).build();
vpnIntfList.remove(vpnIntfs);
if (vpnIntfList.isEmpty()) {
// Remove the DPN as well
removeDpnFromSubnet(subnetId, dpnId);
dpnRemoved = true;
} else {
subDpnBuilder.setVpnInterfaces(vpnIntfList);
SingleTransactionDataBroker.syncWrite(broker, LogicalDatastoreType.OPERATIONAL, dpnOpId, subDpnBuilder.build());
}
LOG.info("removeInterfaceFromDpn: Removed interface {} from sunbet {} dpn {}", intfName, subnetId.getValue(), dpnId);
} catch (TransactionCommitFailedException ex) {
LOG.error("removeInterfaceFromDpn: Deletion of Interface {} for SubnetToDpn on subnet {}" + " with DPN {} failed", intfName, subnetId.getValue(), dpnId, ex);
return false;
}
return dpnRemoved;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.of.object.Of in project netvirt by opendaylight.
the class SubnetOpDpnManager method addInterfaceToDpn.
public SubnetToDpn addInterfaceToDpn(Uuid subnetId, BigInteger dpnId, String intfName) {
SubnetToDpn subDpn = null;
try {
// Create and add SubnetOpDataEntry object for this subnet to the SubnetOpData container
InstanceIdentifier<SubnetOpDataEntry> subOpIdentifier = InstanceIdentifier.builder(SubnetOpData.class).child(SubnetOpDataEntry.class, new SubnetOpDataEntryKey(subnetId)).build();
// Please use a synchronize block here as we donot need a cluster-wide lock
InstanceIdentifier<SubnetToDpn> dpnOpId = subOpIdentifier.child(SubnetToDpn.class, new SubnetToDpnKey(dpnId));
Optional<SubnetToDpn> optionalSubDpn = VpnUtil.read(broker, LogicalDatastoreType.OPERATIONAL, dpnOpId);
if (!optionalSubDpn.isPresent()) {
// Create a new DPN Entry
subDpn = addDpnToSubnet(subnetId, dpnId);
} else {
subDpn = optionalSubDpn.get();
}
SubnetToDpnBuilder subDpnBuilder = new SubnetToDpnBuilder(subDpn);
List<VpnInterfaces> vpnIntfList = subDpnBuilder.getVpnInterfaces();
VpnInterfaces vpnIntfs = new VpnInterfacesBuilder().setKey(new VpnInterfacesKey(intfName)).setInterfaceName(intfName).build();
vpnIntfList.add(vpnIntfs);
subDpnBuilder.setVpnInterfaces(vpnIntfList);
subDpn = subDpnBuilder.build();
SingleTransactionDataBroker.syncWrite(broker, LogicalDatastoreType.OPERATIONAL, dpnOpId, subDpn);
LOG.info("addInterfaceToDpn: Created SubnetToDpn entry for subnet {} with DPNId {} intfName {}", subnetId.getValue(), dpnId, intfName);
} catch (TransactionCommitFailedException ex) {
LOG.error("addInterfaceToDpn: Addition of Interface {} for SubnetToDpn on subnet {} with DPN {} failed", intfName, subnetId.getValue(), dpnId, ex);
return null;
}
return subDpn;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.of.object.Of in project netvirt by opendaylight.
the class ArpNotificationHandler method addMipAdjacency.
private void addMipAdjacency(String vpnName, String vpnInterface, IpAddress srcPrefix, String mipMacAddress, IpAddress dstPrefix) {
LOG.trace("Adding {} adjacency to VPN Interface {} ", srcPrefix, vpnInterface);
InstanceIdentifier<VpnInterface> vpnIfId = VpnUtil.getVpnInterfaceIdentifier(vpnInterface);
InstanceIdentifier<Adjacencies> path = vpnIfId.augmentation(Adjacencies.class);
synchronized (vpnInterface.intern()) {
Optional<Adjacencies> adjacencies = VpnUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, path);
String nextHopIpAddr = null;
String nextHopMacAddress = null;
String ip = srcPrefix.getIpv4Address().getValue();
if (interfaceManager.isExternalInterface(vpnInterface)) {
String subnetId = getSubnetId(vpnName, dstPrefix.getIpv4Address().getValue());
if (subnetId == null) {
LOG.trace("Can't find corresponding subnet for src IP {}, src MAC {}, dst IP {}, in VPN {}", srcPrefix, mipMacAddress, dstPrefix, vpnName);
return;
}
ip = VpnUtil.getIpPrefix(ip);
AdjacencyBuilder newAdjBuilder = new AdjacencyBuilder().setIpAddress(ip).setKey(new AdjacencyKey(ip)).setAdjacencyType(AdjacencyType.PrimaryAdjacency).setMacAddress(mipMacAddress).setSubnetId(new Uuid(subnetId)).setPhysNetworkFunc(true);
List<Adjacency> adjacencyList = adjacencies.isPresent() ? adjacencies.get().getAdjacency() : new ArrayList<>();
adjacencyList.add(newAdjBuilder.build());
Adjacencies aug = VpnUtil.getVpnInterfaceAugmentation(adjacencyList);
Optional<VpnInterface> optionalVpnInterface = VpnUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIfId);
VpnInterface newVpnIntf;
if (optionalVpnInterface.isPresent()) {
newVpnIntf = new VpnInterfaceBuilder(optionalVpnInterface.get()).addAugmentation(Adjacencies.class, aug).build();
VpnUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIfId, newVpnIntf);
}
LOG.debug(" Successfully stored subnetroute Adjacency into VpnInterface {}", vpnInterface);
return;
}
if (adjacencies.isPresent()) {
List<Adjacency> adjacencyList = adjacencies.get().getAdjacency();
ip = VpnUtil.getIpPrefix(ip);
for (Adjacency adjacs : adjacencyList) {
if (adjacs.getAdjacencyType() == AdjacencyType.PrimaryAdjacency) {
if (adjacs.getIpAddress().equals(ip)) {
LOG.error("The MIP {} is already present as a primary adjacency for interface {} vpn {}." + "Skipping adjacency addition.", ip, vpnInterface, vpnName);
return;
}
nextHopIpAddr = adjacs.getIpAddress();
nextHopMacAddress = adjacs.getMacAddress();
break;
}
}
if (nextHopIpAddr != null) {
String rd = VpnUtil.getVpnRd(dataBroker, vpnName);
long label = VpnUtil.getUniqueId(idManager, VpnConstants.VPN_IDPOOL_NAME, VpnUtil.getNextHopLabelKey(rd != null ? rd : vpnName, ip));
if (label == 0) {
LOG.error("Unable to fetch label from Id Manager. Bailing out of adding MIP adjacency {} " + "to vpn interface {} for vpn {}", ip, vpnInterface, vpnName);
return;
}
String nextHopIp = nextHopIpAddr.split("/")[0];
AdjacencyBuilder newAdjBuilder = new AdjacencyBuilder().setIpAddress(ip).setKey(new AdjacencyKey(ip)).setNextHopIpList(Collections.singletonList(nextHopIp)).setAdjacencyType(AdjacencyType.LearntIp);
if (mipMacAddress != null && !mipMacAddress.equalsIgnoreCase(nextHopMacAddress)) {
newAdjBuilder.setMacAddress(mipMacAddress);
}
adjacencyList.add(newAdjBuilder.build());
Adjacencies aug = VpnUtil.getVpnInterfaceAugmentation(adjacencyList);
Optional<VpnInterface> optionalVpnInterface = VpnUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIfId);
VpnInterface newVpnIntf;
if (optionalVpnInterface.isPresent()) {
newVpnIntf = new VpnInterfaceBuilder(optionalVpnInterface.get()).addAugmentation(Adjacencies.class, aug).build();
VpnUtil.syncWrite(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIfId, newVpnIntf);
}
LOG.debug(" Successfully stored subnetroute Adjacency into VpnInterface {}", vpnInterface);
}
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.of.object.Of in project netvirt by opendaylight.
the class SfcProviderTest method getFirstHopSfInterfaceFromRsp.
@Test
public void getFirstHopSfInterfaceFromRsp() {
RspName rspName = new RspName(RSP_NAME);
// Check RSP with no hops
RenderedServicePathBuilder rspBuilder = createRsp(rspName);
Optional<String> ifName = this.sfcProvider.getFirstHopIngressInterfaceFromRsp(rspBuilder.build());
assertFalse(ifName.isPresent());
// Check RSP with no SF name
rspBuilder = createRsp(rspName, true, false, false, false, false, false, false, false);
ifName = this.sfcProvider.getFirstHopIngressInterfaceFromRsp(rspBuilder.build());
assertFalse(ifName.isPresent());
// Check RSP with SF name, but no SFF name
rspBuilder = createRsp(rspName, true, true, false, false, false, false, false, false);
ifName = this.sfcProvider.getFirstHopIngressInterfaceFromRsp(rspBuilder.build());
assertFalse(ifName.isPresent());
// Check RSP with SF name, but SFF doesnt exist
rspBuilder = createRsp(rspName, true, true, true, false, false, false, false, false);
ifName = this.sfcProvider.getFirstHopIngressInterfaceFromRsp(rspBuilder.build());
assertFalse(ifName.isPresent());
// Check RSP with SF and SFF, but SFF has no dictionary
rspBuilder = createRsp(rspName, true, true, true, false, false, true, false, false);
ifName = this.sfcProvider.getFirstHopIngressInterfaceFromRsp(rspBuilder.build());
assertFalse(ifName.isPresent());
// Check RSP with SF and SFF, but SFF has no dictionary entry for SF
rspBuilder = createRsp(rspName, true, true, true, true, false, true, false, false);
ifName = this.sfcProvider.getFirstHopIngressInterfaceFromRsp(rspBuilder.build());
assertFalse(ifName.isPresent());
// Check RSP with SF, SFF name, SFF exists, but has no DPL
rspBuilder = createRsp(rspName, true, true, true, true, true, true, false, false);
ifName = this.sfcProvider.getFirstHopIngressInterfaceFromRsp(rspBuilder.build());
assertFalse(ifName.isPresent());
// Check RSP with Sfm SFF name, SFF exists, has DPL, but not of type LogicalInterfaceLocator
rspBuilder = createRsp(rspName, true, true, true, true, true, true, true, false);
ifName = this.sfcProvider.getFirstHopIngressInterfaceFromRsp(rspBuilder.build());
assertFalse(ifName.isPresent());
// Check RSP when its all created correctly
rspBuilder = createRsp(rspName, true, true, true, true, true, true, true, true);
ifName = this.sfcProvider.getFirstHopIngressInterfaceFromRsp(rspBuilder.build());
assertTrue(ifName.isPresent());
assertEquals(ifName.get(), LOGICAL_IF_NAME);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.of.object.Of in project netvirt by opendaylight.
the class ExternalNetworksChangeListener method associateExternalNetworkWithVPN.
private void associateExternalNetworkWithVPN(Networks network, WriteTransaction writeFlowInvTx) {
List<Uuid> routerIds = network.getRouterIds();
for (Uuid routerId : routerIds) {
// long router = NatUtil.getVpnId(dataBroker, routerId.getValue());
InstanceIdentifier<RouterPorts> routerPortsId = NatUtil.getRouterPortsId(routerId.getValue());
Optional<RouterPorts> optRouterPorts = MDSALUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, routerPortsId);
if (!optRouterPorts.isPresent()) {
LOG.debug("associateExternalNetworkWithVPN : Could not read Router Ports data object with id: {} " + "to handle associate ext nw {}", routerId, network.getId());
continue;
}
RouterPorts routerPorts = optRouterPorts.get();
List<Ports> interfaces = routerPorts.getPorts();
for (Ports port : interfaces) {
String portName = port.getPortName();
BigInteger dpnId = NatUtil.getDpnForInterface(interfaceManager, portName);
if (dpnId.equals(BigInteger.ZERO)) {
LOG.debug("associateExternalNetworkWithVPN : DPN not found for {}, " + "skip handling of ext nw {} association", portName, network.getId());
continue;
}
List<InternalToExternalPortMap> intExtPortMapList = port.getInternalToExternalPortMap();
for (InternalToExternalPortMap ipMap : intExtPortMapList) {
// remove all VPN related entries
floatingIpListener.createNATFlowEntries(dpnId, portName, routerId.getValue(), network.getId(), ipMap, writeFlowInvTx);
}
}
}
// SNAT
for (Uuid routerId : routerIds) {
LOG.debug("associateExternalNetworkWithVPN() : for routerId {}", routerId);
Uuid networkId = network.getId();
if (networkId == null) {
LOG.error("associateExternalNetworkWithVPN : networkId is null for the router ID {}", routerId);
return;
}
final String vpnName = network.getVpnid().getValue();
if (vpnName == null) {
LOG.error("associateExternalNetworkWithVPN : No VPN associated with ext nw {} for router {}", networkId, routerId);
return;
}
BigInteger dpnId = new BigInteger("0");
InstanceIdentifier<RouterToNaptSwitch> routerToNaptSwitch = NatUtil.buildNaptSwitchRouterIdentifier(routerId.getValue());
Optional<RouterToNaptSwitch> rtrToNapt = MDSALUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, routerToNaptSwitch);
if (rtrToNapt.isPresent()) {
dpnId = rtrToNapt.get().getPrimarySwitchId();
}
LOG.debug("associateExternalNetworkWithVPN : got primarySwitch as dpnId{} ", dpnId);
if (dpnId == null || dpnId.equals(BigInteger.ZERO)) {
LOG.warn("associateExternalNetworkWithVPN : primary napt Switch not found for router {} on dpn: {}", routerId, dpnId);
return;
}
Long routerIdentifier = NatUtil.getVpnId(dataBroker, routerId.getValue());
InstanceIdentifierBuilder<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.IpMapping> idBuilder = InstanceIdentifier.builder(IntextIpMap.class).child(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.IpMapping.class, new org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.IpMappingKey(routerIdentifier));
InstanceIdentifier<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.IpMapping> id = idBuilder.build();
Optional<org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.intext.ip.map.IpMapping> ipMapping = MDSALUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, id);
if (ipMapping.isPresent()) {
List<IpMap> ipMaps = ipMapping.get().getIpMap();
for (IpMap ipMap : ipMaps) {
String externalIp = ipMap.getExternalIp();
LOG.debug("associateExternalNetworkWithVPN : Calling advToBgpAndInstallFibAndTsFlows for dpnId {}," + "vpnName {} and externalIp {}", dpnId, vpnName, externalIp);
if (natMode == NatMode.Controller) {
externalRouterListener.advToBgpAndInstallFibAndTsFlows(dpnId, NwConstants.INBOUND_NAPT_TABLE, vpnName, routerIdentifier, routerId.getValue(), externalIp, network.getId(), null, /* external-router */
writeFlowInvTx);
}
}
} else {
LOG.warn("associateExternalNetworkWithVPN : No ipMapping present fot the routerId {}", routerId);
}
long vpnId = NatUtil.getVpnId(dataBroker, vpnName);
// Install 47 entry to point to 21
if (natMode == NatMode.Controller) {
externalRouterListener.installNaptPfibEntriesForExternalSubnets(routerId.getValue(), dpnId, writeFlowInvTx);
if (vpnId != -1) {
LOG.debug("associateExternalNetworkWithVPN : Calling externalRouterListener installNaptPfibEntry " + "for dpnId {} and vpnId {}", dpnId, vpnId);
externalRouterListener.installNaptPfibEntry(dpnId, vpnId, writeFlowInvTx);
}
}
}
}
Aggregations