use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.unreach.destination.object.unreach.destination.obj.Destination in project netvirt by opendaylight.
the class Ipv6NeighborSolicitationTest method testTransmitNeighborSolicitation.
/**
* Test transmitNeighborSolicitation.
*/
@Test
public void testTransmitNeighborSolicitation() {
doReturn(RpcResultBuilder.status(true).buildFuture()).when(pktProcessService).transmitPacket(any(TransmitPacketInput.class));
BigInteger dpnId = BigInteger.valueOf(1);
String macAddr = "08:00:27:FE:8F:95";
boolean retValue;
Ipv6Address srcIpv6Address = new Ipv6Address("2001:db8::1");
Ipv6Address targetIpv6Address = new Ipv6Address("2001:db8::2");
InstanceIdentifier<Node> ncId = InstanceIdentifier.builder(Nodes.class).child(Node.class, new NodeKey(new NodeId("openflow:1"))).build();
NodeConnectorRef nodeRef = new NodeConnectorRef(ncId);
retValue = instance.transmitNeighborSolicitation(dpnId, nodeRef, new MacAddress(macAddr), srcIpv6Address, targetIpv6Address);
assertEquals(true, retValue);
verify(pktProcessService, times(1)).transmitPacket(any(TransmitPacketInput.class));
byte[] expectedPayload = ipv6TestUtils.buildPacket(// Destination MAC
"33 33 00 00 00 02", // Source MAC
"08 00 27 FE 8F 95", // Ethertype - IPv6
"86 DD", // Version 6, traffic class 0, no flowlabel
"60 00 00 00", // Payload length
"00 20", // Next header is ICMPv6
"3A", // Hop limit
"FF", // Source IP
"20 01 0D B8 00 00 00 00 00 00 00 00 00 00 00 01", // Destination IP
"FF 02 00 00 00 00 00 00 00 00 00 01 FF 00 00 02", // ICMPv6 neighbor advertisement.
"87", // Code
"00", // Checksum (valid)
"5E 94", // Flags
"00 00 00 00", // Target Address
"20 01 0D B8 00 00 00 00 00 00 00 00 00 00 00 02", // Type: Source Link-Layer Option
"01", // Option length
"01", // Source Link layer address
"08 00 27 FE 8F 95");
NodeConnectorRef nodeConnectorRef = MDSALUtil.getNodeConnRef(dpnId, "0xfffffffd");
verify(pktProcessService).transmitPacket(new TransmitPacketInputBuilder().setPayload(expectedPayload).setNode(new NodeRef(ncId)).setEgress(nodeRef).setIngress(nodeConnectorRef).build());
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.unreach.destination.object.unreach.destination.obj.Destination in project netvirt by opendaylight.
the class FibUtil method removeFibEntry.
public void removeFibEntry(String rd, String prefix, WriteTransaction writeConfigTxn) {
if (rd == null || rd.isEmpty()) {
LOG.error("Prefix {} not associated with vpn", prefix);
return;
}
LOG.debug("removeFibEntry: Removing fib entry with destination prefix {} from vrf table for rd {}", prefix, rd);
InstanceIdentifier.InstanceIdentifierBuilder<VrfEntry> idBuilder = InstanceIdentifier.builder(FibEntries.class).child(VrfTables.class, new VrfTablesKey(rd)).child(VrfEntry.class, new VrfEntryKey(prefix));
InstanceIdentifier<VrfEntry> vrfEntryId = idBuilder.build();
if (writeConfigTxn != null) {
writeConfigTxn.delete(LogicalDatastoreType.CONFIGURATION, vrfEntryId);
} else {
MDSALUtil.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION, vrfEntryId);
}
LOG.info("removeFibEntry: Removed Fib Entry rd {} prefix {}", rd, prefix);
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.unreach.destination.object.unreach.destination.obj.Destination in project netvirt by opendaylight.
the class FibUtil method removeOrUpdateFibEntry.
/**
* Removes a specific Nexthop from a VrfEntry. If Nexthop to remove is the
* last one in the VrfEntry, then the VrfEntry is removed too.
* @param rd Route-Distinguisher to which the VrfEntry belongs to
* @param prefix Destination of the route
* @param nextHopToRemove Specific nexthop within the Route to be removed.
* If null or empty, then the whole VrfEntry is removed
*/
public void removeOrUpdateFibEntry(String rd, String prefix, String nextHopToRemove, WriteTransaction writeConfigTxn) {
LOG.debug("Removing fib entry with destination prefix {} from vrf table for rd {} nextHop {}", prefix, rd, nextHopToRemove);
// Looking for existing prefix in MDSAL database
InstanceIdentifier<VrfEntry> vrfEntryId = InstanceIdentifier.builder(FibEntries.class).child(VrfTables.class, new VrfTablesKey(rd)).child(VrfEntry.class, new VrfEntryKey(prefix)).build();
Optional<VrfEntry> entry = MDSALUtil.read(dataBroker, LogicalDatastoreType.CONFIGURATION, vrfEntryId);
if (entry.isPresent()) {
final List<RoutePaths> routePaths = entry.get().getRoutePaths();
if (routePaths == null || routePaths.isEmpty()) {
LOG.warn("routePaths is null/empty for given rd {}, prefix {}", rd, prefix);
return;
}
java.util.Optional<RoutePaths> optRoutePath = routePaths.stream().filter(routePath -> routePath.getNexthopAddress().equals(nextHopToRemove)).findFirst();
if (!optRoutePath.isPresent()) {
LOG.error("Unable to find a routePath that contains the given nextHop to remove {}", nextHopToRemove);
return;
}
RoutePaths routePath = optRoutePath.get();
if (routePaths.size() == 1) {
// Remove the whole entry
if (writeConfigTxn != null) {
writeConfigTxn.delete(LogicalDatastoreType.CONFIGURATION, vrfEntryId);
} else {
MDSALUtil.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION, vrfEntryId);
}
LOG.info("Removed Fib Entry rd {} prefix {} nextHop {}", rd, prefix, nextHopToRemove);
} else {
InstanceIdentifier<RoutePaths> routePathsId = FibHelper.buildRoutePathId(rd, prefix, routePath.getNexthopAddress());
// Remove route
MDSALUtil.syncDelete(dataBroker, LogicalDatastoreType.CONFIGURATION, routePathsId);
LOG.info("Removed Route Path rd {} prefix {}, nextHop {}, label {}", rd, prefix, routePath.getNexthopAddress(), routePath.getLabel());
}
} else {
LOG.warn("Could not find VrfEntry for Route-Distinguisher {} prefix {} nexthop {}", rd, prefix, nextHopToRemove);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.unreach.destination.object.unreach.destination.obj.Destination in project netvirt by opendaylight.
the class VrfEntryListener method cleanUpOpDataForFib.
protected void cleanUpOpDataForFib(Long vpnId, String primaryRd, final VrfEntry vrfEntry) {
/* Get interface info from prefix to interface mapping;
Use the interface info to get the corresponding vpn interface op DS entry,
remove the adjacency corresponding to this fib entry.
If adjacency removed is the last adjacency, clean up the following:
- vpn interface from dpntovpn list, dpn if last vpn interface on dpn
- prefix to interface entry
- vpn interface op DS
*/
LOG.debug("Cleanup of prefix {} in VPN {}", vrfEntry.getDestPrefix(), vpnId);
Prefixes prefixInfo = fibUtil.getPrefixToInterface(vpnId, vrfEntry.getDestPrefix());
if (prefixInfo == null) {
List<String> usedRds = VpnExtraRouteHelper.getUsedRds(dataBroker, vpnId, vrfEntry.getDestPrefix());
String usedRd = usedRds.isEmpty() ? primaryRd : usedRds.get(0);
Routes extraRoute = baseVrfEntryHandler.getVpnToExtraroute(vpnId, usedRd, vrfEntry.getDestPrefix());
if (extraRoute != null) {
for (String nextHopIp : extraRoute.getNexthopIpList()) {
LOG.debug("NextHop IP for destination {} is {}", vrfEntry.getDestPrefix(), nextHopIp);
if (nextHopIp != null) {
String ipPrefix;
if (isIpv4Address(nextHopIp)) {
ipPrefix = nextHopIp + NwConstants.IPV4PREFIX;
} else {
ipPrefix = nextHopIp + NwConstants.IPV6PREFIX;
}
prefixInfo = fibUtil.getPrefixToInterface(vpnId, ipPrefix);
checkCleanUpOpDataForFib(prefixInfo, vpnId, primaryRd, vrfEntry, extraRoute);
}
}
}
if (prefixInfo == null) {
java.util.Optional<Long> optionalLabel = FibUtil.getLabelFromRoutePaths(vrfEntry);
if (optionalLabel.isPresent()) {
Long label = optionalLabel.get();
List<String> nextHopAddressList = FibHelper.getNextHopListFromRoutePaths(vrfEntry);
LabelRouteInfo lri = getLabelRouteInfo(label);
if (isPrefixAndNextHopPresentInLri(vrfEntry.getDestPrefix(), nextHopAddressList, lri)) {
PrefixesBuilder prefixBuilder = new PrefixesBuilder();
prefixBuilder.setDpnId(lri.getDpnId());
prefixBuilder.setVpnInterfaceName(lri.getVpnInterfaceName());
prefixBuilder.setIpAddress(lri.getPrefix());
prefixInfo = prefixBuilder.build();
LOG.debug("Fetched labelRouteInfo for label {} interface {} and got dpn {}", label, prefixInfo.getVpnInterfaceName(), lri.getDpnId());
checkCleanUpOpDataForFib(prefixInfo, vpnId, primaryRd, vrfEntry, extraRoute);
}
}
}
} else {
checkCleanUpOpDataForFib(prefixInfo, vpnId, primaryRd, vrfEntry, null);
}
}
use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.unreach.destination.object.unreach.destination.obj.Destination in project netvirt by opendaylight.
the class VrfEntryListener method installIVpnLinkSwitchingFlows.
/*
* Installs the flows in FIB table that, for a given route, do the switching from one VPN to the other.
*/
private void installIVpnLinkSwitchingFlows(final InterVpnLinkDataComposite interVpnLink, final String vpnUuid, final VrfEntry vrfEntry, long vpnTag) {
Preconditions.checkNotNull(interVpnLink, "InterVpnLink cannot be null");
Preconditions.checkArgument(vrfEntry.getRoutePaths() != null && vrfEntry.getRoutePaths().size() == 1);
String destination = vrfEntry.getDestPrefix();
String nextHop = vrfEntry.getRoutePaths().get(0).getNexthopAddress();
String interVpnLinkName = interVpnLink.getInterVpnLinkName();
// using as metadata the LPortTag associated to that vpn in the inter-vpn-link.
if (interVpnLink.getState().or(State.Error) != State.Active) {
LOG.warn("Route to {} with nexthop={} cannot be installed because the interVpnLink {} is not active", destination, nextHop, interVpnLinkName);
return;
}
Optional<Long> optOtherEndpointLportTag = interVpnLink.getOtherEndpointLportTagByVpnName(vpnUuid);
if (!optOtherEndpointLportTag.isPresent()) {
LOG.warn("Could not find suitable LportTag for the endpoint opposite to vpn {} in interVpnLink {}", vpnUuid, interVpnLinkName);
return;
}
List<BigInteger> targetDpns = interVpnLink.getEndpointDpnsByVpnName(vpnUuid);
if (targetDpns.isEmpty()) {
LOG.warn("Could not find DPNs for endpoint opposite to vpn {} in interVpnLink {}", vpnUuid, interVpnLinkName);
return;
}
String[] values = destination.split("/");
String destPrefixIpAddress = values[0];
int prefixLength = values.length == 1 ? 0 : Integer.parseInt(values[1]);
List<MatchInfo> matches = new ArrayList<>();
matches.add(new MatchMetadata(MetaDataUtil.getVpnIdMetadata(vpnTag), MetaDataUtil.METADATA_MASK_VRFID));
matches.add(MatchEthernetType.IPV4);
if (prefixLength != 0) {
matches.add(new MatchIpv4Destination(destPrefixIpAddress, Integer.toString(prefixLength)));
}
List<Instruction> instructions = Arrays.asList(new InstructionWriteMetadata(MetaDataUtil.getMetaDataForLPortDispatcher(optOtherEndpointLportTag.get().intValue(), ServiceIndex.getIndex(NwConstants.L3VPN_SERVICE_NAME, NwConstants.L3VPN_SERVICE_INDEX)), MetaDataUtil.getMetaDataMaskForLPortDispatcher()).buildInstruction(0), new InstructionGotoTable(NwConstants.L3_INTERFACE_TABLE).buildInstruction(1));
int priority = DEFAULT_FIB_FLOW_PRIORITY + prefixLength;
String flowRef = getInterVpnFibFlowRef(interVpnLinkName, destination, nextHop);
Flow flowEntity = MDSALUtil.buildFlowNew(NwConstants.L3_FIB_TABLE, flowRef, priority, flowRef, 0, 0, COOKIE_VM_FIB_TABLE, matches, instructions);
LOG.trace("Installing flow in FIB table for vpn {} interVpnLink {} nextHop {} key {}", vpnUuid, interVpnLink.getInterVpnLinkName(), nextHop, flowRef);
for (BigInteger dpId : targetDpns) {
LOG.debug("Installing flow: VrfEntry=[prefix={} route-paths={}] dpn {} for InterVpnLink {} in FIB", vrfEntry.getDestPrefix(), vrfEntry.getRoutePaths(), dpId, interVpnLink.getInterVpnLinkName());
mdsalManager.installFlow(dpId, flowEntity);
}
}
Aggregations