use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix in project netvirt by opendaylight.
the class FlowClassifierTranslator method buildAcl.
public static Acl buildAcl(SfcFlowClassifier flowClassifier, String sfpName) {
LOG.info("OpenStack Networking SFC pushed Flow classifier : {}", flowClassifier);
AclBuilder aclBuilder = new AclBuilder();
AceBuilder aceBuilder = new AceBuilder();
ActionsBuilder actionsBuilder = new ActionsBuilder();
RedirectToSfcBuilder redirectToSfcBuilder = new RedirectToSfcBuilder();
NeutronPortsBuilder neutronPortsBuilder = new NeutronPortsBuilder();
AceIpBuilder aceIpBuilder = new AceIpBuilder();
DestinationPortRangeBuilder destinationPortRange = new DestinationPortRangeBuilder();
SourcePortRangeBuilder sourcePortRangeBuilder = new SourcePortRangeBuilder();
if (flowClassifier.getUuid() != null) {
if (flowClassifier.getName() != null) {
aclBuilder.setAclName(flowClassifier.getUuid().getValue() + "_" + flowClassifier.getName());
} else {
aclBuilder.setAclName(flowClassifier.getUuid().getValue());
}
}
if (flowClassifier.getEthertype() != null) {
IpPrefix sourceIp = null;
IpPrefix destinationIp = null;
if (flowClassifier.getSourceIpPrefix() != null) {
sourceIp = flowClassifier.getSourceIpPrefix();
}
if (flowClassifier.getDestinationIpPrefix() != null) {
destinationIp = flowClassifier.getDestinationIpPrefix();
}
if (flowClassifier.getEthertype() == EthertypeV4.class) {
AceIpv4Builder aceIpv4Builder = new AceIpv4Builder();
if (sourceIp != null && sourceIp.getIpv4Prefix() != null) {
aceIpv4Builder.setSourceIpv4Network(sourceIp.getIpv4Prefix());
}
if (destinationIp != null && destinationIp.getIpv4Prefix() != null) {
aceIpv4Builder.setDestinationIpv4Network(destinationIp.getIpv4Prefix());
}
aceIpBuilder.setAceIpVersion(aceIpv4Builder.build());
aclBuilder.setAclType(Ipv4Acl.class);
}
if (flowClassifier.getEthertype() == EthertypeV6.class) {
AceIpv6Builder aceIpv6Builder = new AceIpv6Builder();
if (sourceIp != null && sourceIp.getIpv6Prefix() != null) {
aceIpv6Builder.setSourceIpv6Network(sourceIp.getIpv6Prefix());
}
if (sourceIp != null && destinationIp.getIpv6Prefix() != null) {
aceIpv6Builder.setDestinationIpv6Network(destinationIp.getIpv6Prefix());
}
aceIpBuilder.setAceIpVersion(aceIpv6Builder.build());
aclBuilder.setAclType(Ipv6Acl.class);
}
}
if (flowClassifier.getProtocol() != null) {
if (flowClassifier.getProtocol() == ProtocolTcp.class) {
aceIpBuilder.setProtocol(PROTO_TCP);
}
if (flowClassifier.getProtocol() == ProtocolUdp.class) {
aceIpBuilder.setProtocol(PROTO_UDP);
}
}
if (flowClassifier.getSourcePortRangeMin() != null) {
sourcePortRangeBuilder.setLowerPort(new PortNumber(flowClassifier.getSourcePortRangeMin()));
// set source port range only if lower port is specified as it is a mandatory parameter in acl model
aceIpBuilder.setSourcePortRange(sourcePortRangeBuilder.build());
}
if (flowClassifier.getSourcePortRangeMax() != null) {
sourcePortRangeBuilder.setUpperPort(new PortNumber(flowClassifier.getSourcePortRangeMax()));
}
if (flowClassifier.getDestinationPortRangeMin() != null) {
destinationPortRange.setLowerPort(new PortNumber(flowClassifier.getDestinationPortRangeMin()));
// set destination port range only if lower port is specified as it is a mandatory parameter in acl model
aceIpBuilder.setDestinationPortRange(destinationPortRange.build());
}
if (flowClassifier.getDestinationPortRangeMax() != null) {
destinationPortRange.setUpperPort(new PortNumber(flowClassifier.getDestinationPortRangeMax()));
}
if (flowClassifier.getLogicalSourcePort() != null) {
neutronPortsBuilder.setSourcePortUuid(flowClassifier.getLogicalSourcePort().getValue());
}
if (flowClassifier.getLogicalDestinationPort() != null) {
neutronPortsBuilder.setDestinationPortUuid(flowClassifier.getLogicalDestinationPort().getValue());
}
// currently not supported.
// if (flowClassifier.getL7Parameter() != null) {
// }
MatchesBuilder matchesBuilder = new MatchesBuilder();
matchesBuilder.setAceType(aceIpBuilder.build());
matchesBuilder.addAugmentation(NeutronPorts.class, neutronPortsBuilder.build());
// Set redirect-to-rsp action if rsp name is provided
if (sfpName != null) {
redirectToSfcBuilder.setSfpName(sfpName);
actionsBuilder.addAugmentation(RedirectToSfc.class, redirectToSfcBuilder.build());
aceBuilder.setActions(actionsBuilder.build());
}
aceBuilder.setMatches(matchesBuilder.build());
// OpenStack networking-sfc don't pass action information
// with flow classifier. It need to be determined using the
// Port Chain data and then flow calssifier need to be updated
// with the actions.
aceBuilder.setRuleName(aclBuilder.getAclName() + RULE);
aceBuilder.setKey(new AceKey(aceBuilder.getRuleName()));
ArrayList<Ace> aceList = new ArrayList<>();
aceList.add(aceBuilder.build());
AccessListEntriesBuilder accessListEntriesBuilder = new AccessListEntriesBuilder();
accessListEntriesBuilder.setAce(aceList);
aclBuilder.setAccessListEntries(accessListEntriesBuilder.build());
aclBuilder.setKey(new AclKey(aclBuilder.getAclName(), aclBuilder.getAclType()));
LOG.info("Translated ACL Flow classfier : {}", aclBuilder.toString());
return aclBuilder.build();
}
use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix in project netvirt by opendaylight.
the class Ipv6PktHandlerTest method testonPacketReceivedRouterSolicitationWithSingleSubnet.
@Test
public void testonPacketReceivedRouterSolicitationWithSingleSubnet() throws Exception {
VirtualPort intf = Mockito.mock(VirtualPort.class);
when(intf.getMacAddress()).thenReturn("fa:16:3e:4e:18:0c");
when(ifMgrInstance.getInterfaceNameFromTag(anyLong())).thenReturn("ddec9dba-d831-4ad7-84b9-00d7f65f052f");
when(ifMgrInstance.obtainV6Interface(any())).thenReturn(intf);
when(ifMgrInstance.getRouterV6InterfaceForNetwork(any())).thenReturn(intf);
IpAddress gwIpAddress = Mockito.mock(IpAddress.class);
when(gwIpAddress.getIpv4Address()).thenReturn(null);
when(gwIpAddress.getIpv6Address()).thenReturn(new Ipv6Address("2001:db8::1"));
VirtualSubnet v6Subnet = VirtualSubnet.builder().gatewayIp(gwIpAddress).subnetCidr(new IpPrefix("2001:db8::/64".toCharArray())).ipv6AddressMode(Ipv6Constants.IPV6_SLAAC).ipv6RAMode(Ipv6Constants.IPV6_SLAAC).build();
VirtualRouter virtualRouter = VirtualRouter.builder().build();
v6Subnet.setRouter(virtualRouter);
List<VirtualSubnet> subnetList = new ArrayList<>();
subnetList.add(v6Subnet);
when(intf.getSubnets()).thenReturn(subnetList);
InstanceIdentifier<Node> ncId = InstanceIdentifier.builder(Nodes.class).child(Node.class, new NodeKey(new NodeId("openflow:1"))).build();
NodeConnectorRef ncRef = new NodeConnectorRef(ncId);
BigInteger mdata = new BigInteger(String.valueOf(0x1000000));
Metadata metadata = new MetadataBuilder().setMetadata(mdata).build();
MatchBuilder matchbuilder = new MatchBuilder().setMetadata(metadata);
pktHandler.onPacketReceived(new PacketReceivedBuilder().setPayload(ipv6TestUtils.buildPacket(// Destination MAC
"33 33 00 00 00 02", // Source MAC
"FA 16 3E 69 2C F3", // IPv6
"86 DD", // Version 6, traffic class E0, no flowlabel
"60 00 00 00", // Payload length
"00 10", // Next header is ICMPv6
"3A", // Hop limit
"FF", // Source IP
"FE 80 00 00 00 00 00 00 F8 16 3E FF FE 69 2C F3", // Destination IP
"FF 02 00 00 00 00 00 00 00 00 00 00 00 00 00 02", // ICMPv6 router solicitation
"85", // Code
"00", // Checksum (valid)
"B4 47", // ICMPv6 message body
"00 00 00 00", // ICMPv6 Option: Source Link Layer Address
"01", // Length
"01", // Link Layer Address
"FA 16 3E 69 2C F3")).setIngress(ncRef).setMatch(matchbuilder.build()).build());
// wait on this thread until the async job is completed in the packet handler.
waitForPacketProcessing();
verify(pktProcessService, times(1)).transmitPacket(any(TransmitPacketInput.class));
byte[] expectedPayload = ipv6TestUtils.buildPacket(// Destination MAC
"FA 16 3E 69 2C F3", // Source MAC
"FA 16 3E 4E 18 0C", // IPv6
"86 DD", // Version 6, traffic class E0, no flowlabel
"60 00 00 00", // Payload length
"00 38", // Next header is ICMPv6
"3A", // Hop limit
"FF", // Source IP
"FE 80 00 00 00 00 00 00 F8 16 3E FF FE 4E 18 0C", // Destination IP
"FE 80 00 00 00 00 00 00 F8 16 3E FF FE 69 2C F3", // ICMPv6 router advertisement.
"86", // Code
"00", // Checksum (valid)
"1B B0", // Current Hop Limit
"40", // ICMPv6 RA Flags
"00", // Router Lifetime
"11 94", // Reachable time
"00 01 D4 C0", // Retransmission time.
"00 00 00 00", // Type: Source Link-Layer Option
"01", // Option length
"01", // Source Link layer address
"FA 16 3E 4E 18 0C", // Type: Prefix Information
"03", // Option length
"04", // Prefix length
"40", // Prefix flags
"C0", // Valid lifetime
"00 27 8D 00", // Preferred lifetime
"00 09 3A 80", // Reserved
"00 00 00 00", // Prefix
"20 01 0D B8 00 00 00 00 00 00 00 00 00 00 00 00");
verify(pktProcessService).transmitPacket(new TransmitPacketInputBuilder().setPayload(expectedPayload).setNode(new NodeRef(ncId)).setEgress(ncRef).build());
}
use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix in project netvirt by opendaylight.
the class FibRpcServiceImpl method makeLocalFibEntry.
private void makeLocalFibEntry(long vpnId, BigInteger dpnId, String ipPrefix, List<Instruction> customInstructions) {
String[] values = ipPrefix.split("/");
String ipAddress = values[0];
int prefixLength = values.length == 1 ? 0 : Integer.parseInt(values[1]);
LOG.debug("Adding route to DPN. ip {} masklen {}", ipAddress, prefixLength);
InetAddress destPrefix = null;
try {
destPrefix = InetAddress.getByName(ipAddress);
} catch (UnknownHostException e) {
LOG.error("UnknowHostException in addRoute. Failed to add Route for ipPrefix {} VpnId {} DPN{}", ipAddress, vpnId, dpnId, e);
return;
}
List<MatchInfo> matches = new ArrayList<>();
matches.add(new MatchMetadata(MetaDataUtil.getVpnIdMetadata(vpnId), MetaDataUtil.METADATA_MASK_VRFID));
matches.add(MatchEthernetType.IPV4);
if (prefixLength != 0) {
matches.add(new MatchIpv4Destination(destPrefix.getHostAddress(), Integer.toString(prefixLength)));
}
String flowRef = getFlowRef(dpnId, NwConstants.L3_FIB_TABLE, vpnId, ipAddress);
int priority = DEFAULT_FIB_FLOW_PRIORITY + prefixLength;
Flow flowEntity = MDSALUtil.buildFlowNew(NwConstants.L3_FIB_TABLE, flowRef, priority, flowRef, 0, 0, NwConstants.COOKIE_VM_FIB_TABLE, matches, customInstructions);
mdsalManager.installFlow(dpnId, flowEntity);
LOG.debug("FIB entry for route {} on dpn {} installed successfully - flow {}", ipAddress, dpnId, flowEntity);
}
use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix in project netvirt by opendaylight.
the class FibRpcServiceImpl method removeLocalFibEntry.
private void removeLocalFibEntry(BigInteger dpnId, long vpnId, String ipPrefix) {
String[] values = ipPrefix.split("/");
String ipAddress = values[0];
int prefixLength = values.length == 1 ? 0 : Integer.parseInt(values[1]);
LOG.debug("Removing route from DPN. ip {} masklen {}", ipAddress, prefixLength);
InetAddress destPrefix = null;
try {
destPrefix = InetAddress.getByName(ipAddress);
} catch (UnknownHostException e) {
LOG.error("UnknowHostException in removeRoute. Failed to remove Route for ipPrefix {} DPN {} Vpn {}", ipAddress, dpnId, vpnId, e);
return;
}
List<MatchInfo> matches = new ArrayList<>();
matches.add(new MatchMetadata(MetaDataUtil.getVpnIdMetadata(vpnId), MetaDataUtil.METADATA_MASK_VRFID));
matches.add(MatchEthernetType.IPV4);
if (prefixLength != 0) {
matches.add(new MatchIpv4Destination(destPrefix.getHostAddress(), Integer.toString(prefixLength)));
}
String flowRef = getFlowRef(dpnId, NwConstants.L3_FIB_TABLE, vpnId, ipAddress);
int priority = DEFAULT_FIB_FLOW_PRIORITY + prefixLength;
Flow flowEntity = MDSALUtil.buildFlowNew(NwConstants.L3_FIB_TABLE, flowRef, priority, flowRef, 0, 0, NwConstants.COOKIE_VM_FIB_TABLE, matches, null);
mdsalManager.removeFlow(dpnId, flowEntity);
LOG.info("FIB entry for prefix {} on dpn {} vpn {} removed successfully", ipAddress, dpnId, vpnId);
}
use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix 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