use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev200720.pcupd.message.pcupd.message.updates.Path in project netvirt by opendaylight.
the class ArpMonitorStopTask method removeMipAdjacency.
private void removeMipAdjacency(String fixedip, String vpnName, String interfaceName) {
synchronized (interfaceName.intern()) {
InstanceIdentifier<VpnInterface> vpnIfId = VpnUtil.getVpnInterfaceIdentifier(interfaceName);
InstanceIdentifier<Adjacencies> path = vpnIfId.augmentation(Adjacencies.class);
Optional<Adjacencies> adjacencies = VpnUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, path);
if (adjacencies.isPresent()) {
InstanceIdentifier<Adjacency> adid = vpnIfId.augmentation(Adjacencies.class).child(Adjacency.class, new AdjacencyKey(ipToPrefix(fixedip)));
try {
SingleTransactionDataBroker.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION, adid);
} catch (TransactionCommitFailedException e) {
LOG.error("Failed to delete the learned-ip-adjacency for vpn {} interface {} prefix {}", vpnName, interfaceName, ipToPrefix(fixedip), e);
return;
}
LOG.info("Successfully deleted the learned-ip-adjacency prefix {} on vpn {} for interface {}", ipToPrefix(fixedip), vpnName, interfaceName);
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev200720.pcupd.message.pcupd.message.updates.Path 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.ietf.stateful.rev200720.pcupd.message.pcupd.message.updates.Path in project netvirt by opendaylight.
the class AclServiceUtils method getDpnForInterface.
/**
* Get the data path number for the interface.
* @param interfaceManagerRpcService interfaceManagerRpcService instance.
* @param ifName the interface name.
* @return the dpn.
*/
public static BigInteger getDpnForInterface(OdlInterfaceRpcService interfaceManagerRpcService, String ifName) {
BigInteger nodeId = BigInteger.ZERO;
try {
GetDpidFromInterfaceInput dpIdInput = new GetDpidFromInterfaceInputBuilder().setIntfName(ifName).build();
Future<RpcResult<GetDpidFromInterfaceOutput>> dpIdOutput = interfaceManagerRpcService.getDpidFromInterface(dpIdInput);
RpcResult<GetDpidFromInterfaceOutput> dpIdResult = dpIdOutput.get();
if (dpIdResult.isSuccessful()) {
nodeId = dpIdResult.getResult().getDpid();
} else {
LOG.error("Could not retrieve DPN Id for interface {}", ifName);
}
} catch (NullPointerException | InterruptedException | ExecutionException e) {
LOG.error("Exception when getting dpn for interface {}", ifName, e);
}
return nodeId;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev200720.pcupd.message.pcupd.message.updates.Path in project netvirt by opendaylight.
the class NodeConnectedHandlerUtils method addPsNode.
CheckedFuture<Void, TransactionCommitFailedException> addPsNode(InstanceIdentifier<Node> path, InstanceIdentifier<Node> parentPath, List<String> portNameList, WriteTransaction transaction) throws Exception {
NodeBuilder nodeBuilder = null;
nodeBuilder = prepareOperationalNode(path);
PhysicalSwitchAugmentationBuilder physicalSwitchAugmentationBuilder = new PhysicalSwitchAugmentationBuilder();
physicalSwitchAugmentationBuilder.setManagedBy(new HwvtepGlobalRef(parentPath));
physicalSwitchAugmentationBuilder.setPhysicalSwitchUuid(getUUid("d1s3"));
physicalSwitchAugmentationBuilder.setHwvtepNodeName(new HwvtepNodeName("s3"));
physicalSwitchAugmentationBuilder.setHwvtepNodeDescription("description");
List<TunnelIps> tunnelIps = new ArrayList<>();
IpAddress ip = new IpAddress("192.168.122.30".toCharArray());
tunnelIps.add(new TunnelIpsBuilder().setKey(new TunnelIpsKey(ip)).setTunnelIpsKey(ip).build());
physicalSwitchAugmentationBuilder.setTunnelIps(tunnelIps);
nodeBuilder.addAugmentation(PhysicalSwitchAugmentation.class, physicalSwitchAugmentationBuilder.build());
PhysicalSwitchHelper.dId = parentPath;
nodeBuilder.setTerminationPoint(PhysicalSwitchHelper.addPhysicalSwitchTerminationPoints(path, transaction, portNameList));
return TestUtil.submitNode(OPERATIONAL, path, nodeBuilder.build(), transaction);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev200720.pcupd.message.pcupd.message.updates.Path in project netvirt by opendaylight.
the class DhcpExternalTunnelManager method chooseDpn.
/**
* Choose a dpn among the list of elanDpns such that it has lowest count of being the designated dpn.
* @param tunnelIp The tunnel Ip address
* @param elanInstanceName The elan instance name
* @param dpns The data path nodes
* @return The designated dpn
*/
private BigInteger chooseDpn(IpAddress tunnelIp, String elanInstanceName, List<BigInteger> dpns) {
BigInteger designatedDpnId = DhcpMConstants.INVALID_DPID;
if (dpns != null && dpns.size() != 0) {
List<BigInteger> candidateDpns = DhcpServiceUtils.getDpnsForElan(elanInstanceName, broker);
candidateDpns.retainAll(dpns);
LOG.trace("Choosing new dpn for tunnelIp {}, elanInstanceName {}, among elanDpns {}", tunnelIp, elanInstanceName, candidateDpns);
boolean elanDpnAvailableFlag = true;
if (candidateDpns.isEmpty()) {
candidateDpns = dpns;
elanDpnAvailableFlag = false;
}
int size = 0;
L2GatewayDevice device = getDeviceFromTunnelIp(tunnelIp);
if (device == null) {
LOG.trace("Could not find any device for elanInstanceName {} and tunnelIp {}", elanInstanceName, tunnelIp);
handleUnableToDesignateDpn(tunnelIp, elanInstanceName);
return designatedDpnId;
}
for (BigInteger dpn : candidateDpns) {
String hwvtepNodeId = device.getHwvtepNodeId();
if (!elanDpnAvailableFlag) {
if (!isTunnelConfigured(dpn, hwvtepNodeId)) {
LOG.trace("Tunnel is not configured on dpn {} to TOR {}", dpn, hwvtepNodeId);
continue;
}
} else if (!isTunnelUp(hwvtepNodeId, dpn)) {
LOG.trace("Tunnel is not up between dpn {} and TOR {}", dpn, hwvtepNodeId);
continue;
}
Set<Pair<IpAddress, String>> tunnelIpElanNameSet = designatedDpnsToTunnelIpElanNameCache.get(dpn);
if (tunnelIpElanNameSet == null) {
designatedDpnId = dpn;
break;
}
if (size == 0 || tunnelIpElanNameSet.size() < size) {
size = tunnelIpElanNameSet.size();
designatedDpnId = dpn;
}
}
writeDesignatedSwitchForExternalTunnel(designatedDpnId, tunnelIp, elanInstanceName);
return designatedDpnId;
}
handleUnableToDesignateDpn(tunnelIp, elanInstanceName);
return designatedDpnId;
}
Aggregations