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 AclServiceUtils method buildArpIpMatches.
/**
* Builds the arp ip matches.
* @param ipPrefixOrAddress the ip prefix or address
* @return the MatchInfoBase list
*/
public static List<MatchInfoBase> buildArpIpMatches(IpPrefixOrAddress ipPrefixOrAddress) {
List<MatchInfoBase> flowMatches = new ArrayList<>();
IpPrefix ipPrefix = ipPrefixOrAddress.getIpPrefix();
if (ipPrefix != null) {
Ipv4Prefix ipv4Prefix = ipPrefix.getIpv4Prefix();
if (ipv4Prefix != null && !ipv4Prefix.getValue().equals(AclConstants.IPV4_ALL_NETWORK)) {
flowMatches.add(new MatchArpSpa(ipv4Prefix));
}
} else {
IpAddress ipAddress = ipPrefixOrAddress.getIpAddress();
if (ipAddress != null && ipAddress.getIpv4Address() != null) {
flowMatches.add(new MatchArpSpa(ipAddress.getIpv4Address().getValue(), "32"));
}
}
return flowMatches;
}
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 AclServiceUtils method doesIpv6AddressExists.
/**
* Does IPv6 address exists in the list of allowed address pair.
*
* @param aaps the allowed address pairs
* @return true, if successful
*/
public static boolean doesIpv6AddressExists(List<AllowedAddressPairs> aaps) {
if (aaps == null) {
return false;
}
for (AllowedAddressPairs aap : aaps) {
IpPrefixOrAddress ipPrefixOrAddress = aap.getIpAddress();
IpPrefix ipPrefix = ipPrefixOrAddress.getIpPrefix();
if (ipPrefix != null) {
if (ipPrefix.getIpv6Prefix() != null) {
return true;
}
} else {
IpAddress ipAddress = ipPrefixOrAddress.getIpAddress();
if (ipAddress != null && ipAddress.getIpv6Address() != null) {
return true;
}
}
}
return false;
}
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 AclServiceUtils method skipDeleteInCaseOfOverlappingIP.
/**
* Skip delete in case of overlapping IP.
*
* <p>
* When there are multiple ports (e.g., p1, p2, p3) having same AAP (e.g.,
* 224.0.0.5) configured which are part of single SG, there would be single
* flow in remote ACL table. When one of these ports (say p1) is deleted,
* the single flow which is configured in remote ACL table shouldn't be
* deleted. It should be deleted only when there are no more references to
* it.
*
* @param portId the port id
* @param remoteAclId the remote Acl Id
* @param ipPrefix the ip prefix
* @param addOrRemove the add or remove
* @return true, if successful
*/
public boolean skipDeleteInCaseOfOverlappingIP(String portId, Uuid remoteAclId, IpPrefixOrAddress ipPrefix, int addOrRemove) {
boolean skipDelete = false;
if (addOrRemove != NwConstants.DEL_FLOW) {
return skipDelete;
}
AclIpPrefixes aclIpPrefixes = getAclIpPrefixesFromOperDs(remoteAclId.getValue(), ipPrefix);
if (aclIpPrefixes != null && aclIpPrefixes.getPortIds() != null) {
List<String> ignorePorts = Lists.newArrayList(portId);
List<PortIds> portIds = new ArrayList<>(aclIpPrefixes.getPortIds());
// Checking if there are any other ports excluding ignorePorts
long noOfRemotePorts = portIds.stream().map(x -> x.getPortId()).filter(y -> !ignorePorts.contains(y)).count();
if (noOfRemotePorts > 0) {
skipDelete = true;
}
}
return skipDelete;
}
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 NatUtil method addPrefixToInterface.
static void addPrefixToInterface(DataBroker broker, long vpnId, String interfaceName, String ipPrefix, BigInteger dpId, Uuid subnetId, Prefixes.PrefixCue prefixCue) {
InstanceIdentifier<Prefixes> prefixId = InstanceIdentifier.builder(PrefixToInterface.class).child(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.prefix.to._interface.VpnIds.class, new org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.prefix.to._interface.VpnIdsKey(vpnId)).child(Prefixes.class, new PrefixesKey(ipPrefix)).build();
PrefixesBuilder prefixBuilder = new PrefixesBuilder().setDpnId(dpId).setIpAddress(ipPrefix);
prefixBuilder.setVpnInterfaceName(interfaceName).setSubnetId(subnetId).setPrefixCue(prefixCue);
try {
SingleTransactionDataBroker.syncWrite(broker, LogicalDatastoreType.OPERATIONAL, prefixId, prefixBuilder.build());
} catch (TransactionCommitFailedException e) {
LOG.error("addPrefixToInterface : Failed to write prefxi-to-interface for {} vpn-id {} DPN {}", ipPrefix, vpnId, dpId, e);
}
}
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 testonPacketReceivedRouterSolicitationWithMultipleSubnets.
@Test
public void testonPacketReceivedRouterSolicitationWithMultipleSubnets() throws Exception {
VirtualPort intf = Mockito.mock(VirtualPort.class);
when(intf.getMacAddress()).thenReturn("50:7B:9D:78:54:F3");
when(ifMgrInstance.obtainV6Interface(any())).thenReturn(intf);
when(ifMgrInstance.getInterfaceNameFromTag(anyLong())).thenReturn("ddec9dba-d831-4ad7-84b9-00d7f65f052f");
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:1111::1"));
VirtualSubnet v6Subnet1 = VirtualSubnet.builder().gatewayIp(gwIpAddress).subnetCidr(new IpPrefix("2001:db8:1111::/64".toCharArray())).ipv6AddressMode(Ipv6Constants.IPV6_SLAAC).ipv6RAMode(Ipv6Constants.IPV6_SLAAC).build();
VirtualRouter virtualRouter = VirtualRouter.builder().build();
v6Subnet1.setRouter(virtualRouter);
VirtualSubnet v6Subnet2 = VirtualSubnet.builder().gatewayIp(gwIpAddress).subnetCidr(new IpPrefix("2001:db8:2222::/64".toCharArray())).ipv6AddressMode(Ipv6Constants.IPV6_DHCPV6_STATELESS).ipv6RAMode(Ipv6Constants.IPV6_DHCPV6_STATELESS).build();
v6Subnet2.setRouter(virtualRouter);
VirtualSubnet v6Subnet3 = VirtualSubnet.builder().gatewayIp(gwIpAddress).subnetCidr(new IpPrefix("2001:db8:3333::/64".toCharArray())).ipv6AddressMode(Ipv6Constants.IPV6_DHCPV6_STATEFUL).ipv6RAMode(Ipv6Constants.IPV6_DHCPV6_STATEFUL).build();
v6Subnet3.setRouter(virtualRouter);
List<VirtualSubnet> subnetList = new ArrayList<>();
subnetList.add(v6Subnet1);
subnetList.add(v6Subnet2);
subnetList.add(v6Subnet3);
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
"50 7B 9D 78 54 F3", // IPv6
"86 DD", // Version 6, traffic class E0, no flowlabel
"60 00 00 00", // Payload length
"00 78", // Next header is ICMPv6
"3A", // Hop limit
"FF", // Source IP
"FE 80 00 00 00 00 00 00 52 7B 9D FF FE 78 54 F3", // 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)
"59 41", // Current Hop Limit
"40", // ICMPv6 RA Flags
"C0", // 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
"50 7B 9D 78 54 F3", // 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 11 11 00 00 00 00 00 00 00 00 00 00", // 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 22 22 00 00 00 00 00 00 00 00 00 00", // Type: Prefix Information
"03", // Option length
"04", // Prefix length
"40", // Prefix flags
"80", // Valid lifetime
"00 27 8D 00", // Preferred lifetime
"00 09 3A 80", // Reserved
"00 00 00 00", // Prefix
"20 01 0D B8 33 33 00 00 00 00 00 00 00 00 00 00");
verify(pktProcessService).transmitPacket(new TransmitPacketInputBuilder().setPayload(expectedPayload).setNode(new NodeRef(ncId)).setEgress(ncRef).build());
}
Aggregations