use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.adjacency.list.Adjacency in project netvirt by opendaylight.
the class ArpNotificationHandler method onArpResponseReceived.
@Override
public void onArpResponseReceived(ArpResponseReceived notification) {
String srcInterface = notification.getInterface();
IpAddress srcIP = notification.getSrcIpaddress();
PhysAddress srcMac = notification.getSrcMac();
LOG.info("ArpNotification Response Received from interface {} and IP {} having MAC {}, learning MAC", srcInterface, srcIP.getIpv4Address().getValue(), srcMac.getValue());
List<Adjacency> adjacencies = VpnUtil.getAdjacenciesForVpnInterfaceFromConfig(dataBroker, srcInterface);
if (adjacencies != null) {
for (Adjacency adj : adjacencies) {
String ipAddress = adj.getIpAddress();
try {
if (NWUtil.isIpInSubnet(NWUtil.ipAddressToInt(srcIP.getIpv4Address().getValue()), ipAddress)) {
return;
}
} catch (UnknownHostException e) {
LOG.error("Subnet string {} not convertible to InetAdddress", srcIP, e);
}
}
}
BigInteger metadata = notification.getMetadata();
IpAddress targetIP = notification.getDstIpaddress();
LOG.trace("ArpNotification Response Received from interface {} and IP {} having MAC {}, learning MAC", srcInterface, srcIP.getIpv4Address().getValue(), srcMac.getValue());
processArpLearning(srcInterface, srcIP, srcMac, metadata, targetIP);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.adjacency.list.Adjacency in project netvirt by opendaylight.
the class ArpNotificationHandler method getSubnetId.
private String getSubnetId(String vpnName, String ip) {
// Check if this IP belongs to a router_interface
VpnPortipToPort vpnPortipToPort = VpnUtil.getNeutronPortFromVpnPortFixedIp(dataBroker, vpnName, ip);
if (vpnPortipToPort != null && vpnPortipToPort.isSubnetIp()) {
List<Adjacency> adjacecnyList = VpnUtil.getAdjacenciesForVpnInterfaceFromConfig(dataBroker, vpnPortipToPort.getPortName());
for (Adjacency adjacency : adjacecnyList) {
if (adjacency.getAdjacencyType() == AdjacencyType.PrimaryAdjacency) {
return adjacency.getSubnetId().getValue();
}
}
}
// Check if this IP belongs to a router_gateway
List<Uuid> routerIds = VpnUtil.getExternalNetworkRouterIds(dataBroker, new Uuid(vpnName));
for (Uuid routerId : routerIds) {
Uuid subnetId = VpnUtil.getSubnetFromExternalRouterByIp(dataBroker, routerId, ip);
if (subnetId != null) {
return subnetId.getValue();
}
}
return null;
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.adjacency.list.Adjacency in project netvirt by opendaylight.
the class EvpnDnatFlowProgrammer method onAddFloatingIp.
public void onAddFloatingIp(final BigInteger dpnId, final String routerName, final long routerId, final String vpnName, final String internalIp, final String externalIp, final Uuid networkId, final String interfaceName, final String floatingIpInterface, final String floatingIpPortMacAddress, final String rd, final String nextHopIp, final WriteTransaction writeFlowInvTx) {
/*
* 1) Install the flow INTERNAL_TUNNEL_TABLE (table=36)-> PDNAT_TABLE (table=25) (SNAT VM on DPN1 is
* responding back to FIP VM on DPN2) {SNAT to DNAT traffic on different Hypervisor}
*
* 2) Install the flow L3_FIB_TABLE (table=21)-> PDNAT_TABLE (table=25) (FIP VM1 to FIP VM2
* Traffic on Same Hypervisor) {DNAT to DNAT on Same Hypervisor}
*
* 3) Install the flow L3_GW_MAC_TABLE (table=19)-> PDNAT_TABLE (table=25)
* (DC-GW is responding back to FIP VM) {DNAT Reverse traffic})
*
*/
long vpnId = NatUtil.getVpnId(dataBroker, vpnName);
if (vpnId == NatConstants.INVALID_ID) {
LOG.error("onAddFloatingIp : Invalid Vpn Id is found for Vpn Name {}", vpnName);
return;
}
long l3Vni = NatEvpnUtil.getL3Vni(dataBroker, rd);
if (l3Vni == NatConstants.DEFAULT_L3VNI_VALUE) {
LOG.debug("onAddFloatingIp : L3VNI value is not configured in Internet VPN {} and RD {} " + "Carve-out L3VNI value from OpenDaylight VXLAN VNI Pool and continue with installing " + "DNAT flows for FloatingIp {}", vpnName, rd, externalIp);
l3Vni = NatOverVxlanUtil.getInternetVpnVni(idManager, vpnName, routerId).longValue();
}
FloatingIPListener.updateOperationalDS(dataBroker, routerName, interfaceName, NatConstants.DEFAULT_LABEL_VALUE, internalIp, externalIp);
String fibExternalIp = NatUtil.validateAndAddNetworkMask(externalIp);
// Inform to FIB and BGP
NatEvpnUtil.addRoutesForVxLanProvType(dataBroker, bgpManager, fibManager, vpnName, rd, fibExternalIp, nextHopIp, l3Vni, floatingIpInterface, floatingIpPortMacAddress, writeFlowInvTx, RouteOrigin.STATIC, dpnId);
/* Install the flow table L3_FIB_TABLE (table=21)-> PDNAT_TABLE (table=25)
* (SNAT to DNAT reverse traffic: If the DPN has both SNAT and DNAT configured )
*/
List<ActionInfo> actionInfoFib = new ArrayList<>();
actionInfoFib.add(new ActionSetFieldEthernetDestination(new MacAddress(floatingIpPortMacAddress)));
List<Instruction> instructionsFib = new ArrayList<>();
instructionsFib.add(new InstructionApplyActions(actionInfoFib).buildInstruction(0));
instructionsFib.add(new InstructionGotoTable(NwConstants.PDNAT_TABLE).buildInstruction(1));
CreateFibEntryInput input = new CreateFibEntryInputBuilder().setVpnName(vpnName).setSourceDpid(dpnId).setIpAddress(fibExternalIp).setServiceId(l3Vni).setIpAddressSource(CreateFibEntryInput.IpAddressSource.FloatingIP).setInstruction(instructionsFib).build();
Future<RpcResult<Void>> future1 = fibService.createFibEntry(input);
ListenableFuture<RpcResult<Void>> futureVxlan = JdkFutureAdapters.listenInPoolThread(future1);
LOG.debug("onAddFloatingIp : Add Floating Ip {} , found associated to fixed port {}", externalIp, interfaceName);
if (floatingIpPortMacAddress != null) {
WriteTransaction writeTx = dataBroker.newWriteOnlyTransaction();
vpnManager.addSubnetMacIntoVpnInstance(vpnName, null, floatingIpPortMacAddress, dpnId, writeTx);
vpnManager.addArpResponderFlowsToExternalNetworkIps(routerName, Collections.singleton(externalIp), floatingIpPortMacAddress, dpnId, networkId, writeTx);
writeTx.submit();
}
final long finalL3Vni = l3Vni;
Futures.addCallback(futureVxlan, new FutureCallback<RpcResult<Void>>() {
@Override
public void onFailure(@Nonnull Throwable error) {
LOG.error("onAddFloatingIp : Error {} in custom fib routes install process for Floating " + "IP Prefix {} on DPN {}", error, externalIp, dpnId);
}
@Override
public void onSuccess(@Nonnull RpcResult<Void> result) {
if (result.isSuccessful()) {
LOG.info("onAddFloatingIp : Successfully installed custom FIB routes for Floating " + "IP Prefix {} on DPN {}", externalIp, dpnId);
List<Instruction> instructions = new ArrayList<>();
List<ActionInfo> actionsInfos = new ArrayList<>();
List<Instruction> customInstructions = new ArrayList<>();
customInstructions.add(new InstructionGotoTable(NwConstants.PDNAT_TABLE).buildInstruction(0));
actionsInfos.add(new ActionNxResubmit(NwConstants.PDNAT_TABLE));
instructions.add(new InstructionApplyActions(actionsInfos).buildInstruction(0));
/* If more than one floatingIp is available in vpn-to-dpn-list for given dpn id, do not call for
* installing INTERNAL_TUNNEL_TABLE (table=36) -> PDNAT_TABLE (table=25) flow entry with same tunnel_id
* again and again.
*/
if (!NatUtil.isFloatingIpPresentForDpn(dataBroker, dpnId, rd, vpnName, externalIp, true)) {
makeTunnelTableEntry(dpnId, finalL3Vni, instructions, writeFlowInvTx);
}
/* Install the flow L3_GW_MAC_TABLE (table=19)-> PDNAT_TABLE (table=25)
* (DNAT reverse traffic: If the traffic is Initiated from DC-GW to FIP VM (DNAT forward traffic))
*/
NatEvpnUtil.makeL3GwMacTableEntry(dpnId, vpnId, floatingIpPortMacAddress, customInstructions, mdsalManager, writeFlowInvTx);
NatUtil.waitForTransactionToComplete(writeFlowInvTx);
} else {
LOG.error("onAddFloatingIp : Error {} in rpc call to create custom Fib entries for Floating " + "IP Prefix {} on DPN {}", result.getErrors(), externalIp, dpnId);
}
}
}, MoreExecutors.directExecutor());
// Read the FIP vpn-interface details from Configuration l3vpn:vpn-interfaces model and write into Operational DS
InstanceIdentifier<VpnInterface> vpnIfIdentifier = NatUtil.getVpnInterfaceIdentifier(floatingIpInterface);
Optional<VpnInterface> optionalVpnInterface = SingleTransactionDataBroker.syncReadOptionalAndTreatReadFailedExceptionAsAbsentOptional(dataBroker, LogicalDatastoreType.CONFIGURATION, vpnIfIdentifier);
if (optionalVpnInterface.isPresent()) {
WriteTransaction writeOperTxn = dataBroker.newWriteOnlyTransaction();
for (VpnInstanceNames vpnInstance : optionalVpnInterface.get().getVpnInstanceNames()) {
if (!vpnName.equals(vpnInstance.getVpnName())) {
continue;
}
VpnInterfaceBuilder vpnIfBuilder = new VpnInterfaceBuilder(optionalVpnInterface.get());
Adjacencies adjs = vpnIfBuilder.getAugmentation(Adjacencies.class);
VpnInterfaceOpDataEntryBuilder vpnIfOpDataEntryBuilder = new VpnInterfaceOpDataEntryBuilder();
vpnIfOpDataEntryBuilder.setKey(new VpnInterfaceOpDataEntryKey(interfaceName, vpnName));
List<Adjacency> adjacencyList = adjs != null ? adjs.getAdjacency() : new ArrayList<>();
List<Adjacency> adjacencyListToImport = new ArrayList<>();
for (Adjacency adj : adjacencyList) {
Subnetmap sn = VpnHelper.getSubnetmapFromItsUuid(dataBroker, adj.getSubnetId());
if (!VpnHelper.isSubnetPartOfVpn(sn, vpnName)) {
continue;
}
adjacencyListToImport.add(adj);
}
AdjacenciesOp adjacenciesOp = new AdjacenciesOpBuilder().setAdjacency(adjacencyListToImport).build();
vpnIfOpDataEntryBuilder.addAugmentation(AdjacenciesOp.class, adjacenciesOp);
LOG.debug("onAddFloatingIp : Add vpnInterface {} to Operational l3vpn:vpn-interfaces-op-data ", floatingIpInterface);
InstanceIdentifier<VpnInterfaceOpDataEntry> vpnIfIdentifierOpDataEntry = NatUtil.getVpnInterfaceOpDataEntryIdentifier(interfaceName, vpnName);
writeOperTxn.put(LogicalDatastoreType.OPERATIONAL, vpnIfIdentifierOpDataEntry, vpnIfOpDataEntryBuilder.build(), WriteTransaction.CREATE_MISSING_PARENTS);
break;
}
ListenableFuture<Void> futures = writeOperTxn.submit();
String errorText = "onAddFloatingIp : Could not write Interface " + interfaceName + " vpnName " + vpnName;
ListenableFutures.addErrorLogging(futures, LOG, errorText);
} else {
LOG.debug("onAddFloatingIp : No vpnInterface {} found in Configuration l3vpn:vpn-interfaces ", floatingIpInterface);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.adjacency.list.Adjacency in project netvirt by opendaylight.
the class FibUtil method updateUsedRdAndVpnToExtraRoute.
public void updateUsedRdAndVpnToExtraRoute(WriteTransaction writeOperTxn, String tunnelIpRemoved, String primaryRd, String prefix) {
Optional<VpnInstanceOpDataEntry> optVpnInstance = getVpnInstanceOpData(primaryRd);
if (!optVpnInstance.isPresent()) {
return;
}
VpnInstanceOpDataEntry vpnInstance = optVpnInstance.get();
String vpnName = vpnInstance.getVpnInstanceName();
long vpnId = vpnInstance.getVpnId();
List<String> usedRds = VpnExtraRouteHelper.getUsedRds(dataBroker, vpnId, prefix);
// which rd is allocated for the particular OVS.
for (String usedRd : usedRds) {
Optional<Routes> vpnExtraRoutes = VpnExtraRouteHelper.getVpnExtraroutes(dataBroker, vpnName, usedRd, prefix);
if (vpnExtraRoutes.isPresent()) {
// Since all the nexthops under one OVS will be present under one rd, only 1 nexthop is read
// to identify the OVS
String nextHopRemoved = vpnExtraRoutes.get().getNexthopIpList().get(0);
Prefixes prefixToInterface = getPrefixToInterface(vpnId, getIpPrefix(nextHopRemoved));
if (prefixToInterface != null && tunnelIpRemoved.equals(getEndpointIpAddressForDPN(prefixToInterface.getDpnId()))) {
InstanceIdentifier<Adjacency> adjId = getAdjacencyIdentifier(prefixToInterface.getVpnInterfaceName(), prefix);
Interface ifState = getInterfaceStateFromOperDS(prefixToInterface.getVpnInterfaceName());
// Delete datastore only if extra route is deleted or VM interface is deleted/down
if (!MDSALUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, adjId).isPresent() || ifState == null || ifState.getOperStatus() == OperStatus.Down) {
writeOperTxn.delete(LogicalDatastoreType.OPERATIONAL, getAdjacencyIdentifier(prefixToInterface.getVpnInterfaceName(), prefix));
writeOperTxn.delete(LogicalDatastoreType.OPERATIONAL, VpnExtraRouteHelper.getVpnToExtrarouteVrfIdIdentifier(vpnName, usedRd, prefix));
writeOperTxn.delete(LogicalDatastoreType.CONFIGURATION, VpnExtraRouteHelper.getUsedRdsIdentifier(vpnId, prefix, nextHopRemoved));
break;
}
}
}
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.l3vpn.rev200204.adjacency.list.Adjacency in project netvirt by opendaylight.
the class VrfEntryListener method createLocalFibEntry.
private List<BigInteger> createLocalFibEntry(Long vpnId, String rd, VrfEntry vrfEntry) {
List<BigInteger> returnLocalDpnId = new ArrayList<>();
String localNextHopIP = vrfEntry.getDestPrefix();
Prefixes localNextHopInfo = fibUtil.getPrefixToInterface(vpnId, localNextHopIP);
String vpnName = fibUtil.getVpnNameFromId(vpnId);
if (localNextHopInfo == null) {
List<String> usedRds = VpnExtraRouteHelper.getUsedRds(dataBroker, vpnId, localNextHopIP);
List<Routes> vpnExtraRoutes = VpnExtraRouteHelper.getAllVpnExtraRoutes(dataBroker, vpnName, usedRds, localNextHopIP);
boolean localNextHopSeen = false;
// Is this fib route an extra route? If yes, get the nexthop which would be an adjacency in the vpn
for (Routes vpnExtraRoute : vpnExtraRoutes) {
String ipPrefix;
if (isIpv4Address(vpnExtraRoute.getNexthopIpList().get(0))) {
ipPrefix = vpnExtraRoute.getNexthopIpList().get(0) + NwConstants.IPV4PREFIX;
} else {
ipPrefix = vpnExtraRoute.getNexthopIpList().get(0) + NwConstants.IPV6PREFIX;
}
Prefixes localNextHopInfoLocal = fibUtil.getPrefixToInterface(vpnId, ipPrefix);
if (localNextHopInfoLocal != null) {
localNextHopSeen = true;
BigInteger dpnId = checkCreateLocalFibEntry(localNextHopInfoLocal, localNextHopInfoLocal.getIpAddress(), vpnId, rd, vrfEntry, vpnId, vpnExtraRoute, vpnExtraRoutes);
returnLocalDpnId.add(dpnId);
}
}
if (!localNextHopSeen && RouteOrigin.value(vrfEntry.getOrigin()) == RouteOrigin.SELF_IMPORTED) {
java.util.Optional<Long> optionalLabel = FibUtil.getLabelFromRoutePaths(vrfEntry);
if (optionalLabel.isPresent()) {
Long label = optionalLabel.get();
List<String> nextHopAddressList = FibHelper.getNextHopListFromRoutePaths(vrfEntry);
synchronized (label.toString().intern()) {
LabelRouteInfo lri = getLabelRouteInfo(label);
if (isPrefixAndNextHopPresentInLri(localNextHopIP, nextHopAddressList, lri)) {
Optional<VpnInstanceOpDataEntry> vpnInstanceOpDataEntryOptional = fibUtil.getVpnInstanceOpData(rd);
if (vpnInstanceOpDataEntryOptional.isPresent()) {
String vpnInstanceName = vpnInstanceOpDataEntryOptional.get().getVpnInstanceName();
if (lri.getVpnInstanceList().contains(vpnInstanceName)) {
localNextHopInfo = updateVpnReferencesInLri(lri, vpnInstanceName, true);
localNextHopIP = lri.getPrefix();
} else {
localNextHopInfo = updateVpnReferencesInLri(lri, vpnInstanceName, false);
localNextHopIP = lri.getPrefix();
}
}
if (localNextHopInfo != null) {
LOG.debug("Fetched labelRouteInfo for label {} interface {} and got dpn {}", label, localNextHopInfo.getVpnInterfaceName(), lri.getDpnId());
if (vpnExtraRoutes.isEmpty()) {
BigInteger dpnId = checkCreateLocalFibEntry(localNextHopInfo, localNextHopIP, vpnId, rd, vrfEntry, lri.getParentVpnid(), null, vpnExtraRoutes);
returnLocalDpnId.add(dpnId);
} else {
for (Routes extraRoutes : vpnExtraRoutes) {
BigInteger dpnId = checkCreateLocalFibEntry(localNextHopInfo, localNextHopIP, vpnId, rd, vrfEntry, lri.getParentVpnid(), extraRoutes, vpnExtraRoutes);
returnLocalDpnId.add(dpnId);
}
}
}
}
}
}
}
if (returnLocalDpnId.isEmpty()) {
LOG.error("Local DPNID is empty for rd {}, vpnId {}, vrfEntry {}", rd, vpnId, vrfEntry);
}
} else {
BigInteger dpnId = checkCreateLocalFibEntry(localNextHopInfo, localNextHopIP, vpnId, rd, vrfEntry, vpnId, /*routes*/
null, /*vpnExtraRoutes*/
null);
if (dpnId != null) {
returnLocalDpnId.add(dpnId);
}
}
return returnLocalDpnId;
}
Aggregations