Search in sources :

Example 1 with Ipv6Address

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address in project OpenAM by OpenRock.

the class ResourceEnvIPCondition method getAdviceStrForEnv.

/**
     * Returns the advice string that satisfies or matches for the client
     * environment parameter, including client's IP Address.
     */
private String getAdviceStrForEnv(Map env, SSOToken token) throws PolicyException, SSOException {
    String adviceStr = null;
    //Check if all the keys are valid
    for (int i = 0; i < envList.size(); i++) {
        String key = (String) envList.get(i);
        if (key != null) {
            if (key.contains("=")) {
                StringTokenizer st = new StringTokenizer(key, "=");
                int tokenCount = st.countTokens();
                if (tokenCount != 2) {
                    String[] args = { key };
                    throw new PolicyException(ResBundleUtils.rbName, "invalid_property_value", args, null);
                }
                String envParamName = st.nextToken().trim();
                String envParamValue = envParamName;
                if (tokenCount == 2) {
                    envParamValue = st.nextToken().trim();
                }
                Set envSet = (Set) env.get(envParamName);
                String strEnv = null;
                if ((envSet != null) && (!envSet.isEmpty())) {
                    Iterator names = envSet.iterator();
                    while (names.hasNext()) {
                        strEnv = (String) names.next();
                        if ((strEnv != null) && (strEnv.equalsIgnoreCase(envParamValue))) {
                            adviceStr = (String) adviceList.get(i);
                            break;
                        }
                    }
                } else {
                    String strIP = null;
                    Object object = env.get(REQUEST_IP);
                    if (object instanceof Set) {
                        Set ipSet = (Set) object;
                        if (ipSet.isEmpty()) {
                            if (token != null) {
                                strIP = token.getIPAddress().getHostAddress();
                            } else {
                                throw new PolicyException(ResBundleUtils.rbName, "client_ip_null", null, null);
                            }
                        } else {
                            Iterator names = ipSet.iterator();
                            strIP = (String) names.next();
                        }
                    } else if (object instanceof String) {
                        strIP = (String) object;
                        if (StringUtils.isBlank(strIP)) {
                            if (token != null) {
                                strIP = token.getIPAddress().getHostAddress();
                            } else {
                                throw new PolicyException(ResBundleUtils.rbName, "client_ip_null", null, null);
                            }
                        }
                    }
                    long requestIpV4 = 0;
                    IPv6Address requestIpV6 = null;
                    if (ValidateIPaddress.isIPv4(strIP)) {
                        requestIpV4 = stringToIp(strIP);
                    } else if (ValidateIPaddress.isIPv6(strIP)) {
                        requestIpV6 = IPv6Address.fromString(strIP);
                    } else {
                        if (DEBUG.messageEnabled()) {
                            DEBUG.message("ResourceEnvIPCondition:getAdviceStrForEnv invalid strIP : " + strIP);
                        }
                        continue;
                    }
                    int bIndex = envParamValue.indexOf("[");
                    int lIndex = envParamValue.indexOf("]");
                    String ipVal = envParamValue.substring(bIndex + 1, lIndex);
                    if (ipVal.contains("-")) {
                        StringTokenizer stIP = new StringTokenizer(ipVal, "-");
                        int tokenCnt = stIP.countTokens();
                        if (tokenCnt > 2) {
                            String[] args = { ipVal };
                            throw new PolicyException(ResBundleUtils.rbName, "invalid_property_value", args, null);
                        }
                        String startIp = stIP.nextToken();
                        String endIp = startIp;
                        if (tokenCnt == 2) {
                            endIp = stIP.nextToken();
                        }
                        if (ValidateIPaddress.isIPv4(strIP) && ValidateIPaddress.isIPv4(startIp) && ValidateIPaddress.isIPv4(endIp)) {
                            long lStartIP = stringToIp(startIp);
                            long lEndIP = stringToIp(endIp);
                            if ((requestIpV4 >= lStartIP) && (requestIpV4 <= lEndIP)) {
                                adviceStr = (String) adviceList.get(i);
                                break;
                            }
                        } else if (ValidateIPaddress.isIPv6(strIP) && ValidateIPaddress.isIPv6(startIp) && ValidateIPaddress.isIPv6(endIp)) {
                            IPv6AddressRange ipv6Range = IPv6AddressRange.fromFirstAndLast(IPv6Address.fromString(startIp), IPv6Address.fromString(endIp));
                            if (requestIpV6 != null && ipv6Range.contains(requestIpV6)) {
                                adviceStr = (String) adviceList.get(i);
                                break;
                            }
                        } else {
                            String[] args = { strIP };
                            throw new PolicyException(ResBundleUtils.rbName, "invalid_property_value", args, null);
                        }
                    } else if (requestIpV4 != 0 && ValidateIPaddress.isIPv4(ipVal)) {
                        long longIp = stringToIp(ipVal);
                        if (requestIpV4 == longIp) {
                            adviceStr = (String) adviceList.get(i);
                            break;
                        }
                    } else if (requestIpV6 != null && ValidateIPaddress.isIPv6(ipVal)) {
                        // treat as single ip address
                        IPv6Address iPv6AddressIpVal = IPv6Address.fromString(ipVal);
                        if (iPv6AddressIpVal.compareTo(requestIpV6) == 0) {
                            adviceStr = (String) adviceList.get(i);
                            break;
                        }
                    } else if (ipVal.contains("*")) {
                        adviceStr = (String) adviceList.get(i);
                        break;
                    } else {
                        String[] args = { ipVal };
                        throw new PolicyException(ResBundleUtils.rbName, "resource_env_not_known", args, null);
                    }
                }
            } else {
                String[] args = { key };
                throw new PolicyException(ResBundleUtils.rbName, "resource_env_not_known", args, null);
            }
        }
    }
    return adviceStr;
}
Also used : StringTokenizer(java.util.StringTokenizer) HashSet(java.util.HashSet) Set(java.util.Set) IPv6AddressRange(com.googlecode.ipv6.IPv6AddressRange) PolicyException(com.sun.identity.policy.PolicyException) Iterator(java.util.Iterator) IPv6Address(com.googlecode.ipv6.IPv6Address)

Example 2 with Ipv6Address

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address 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());
}
Also used : NodeConnectorRef(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef) MetadataBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.MetadataBuilder) TransmitPacketInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.TransmitPacketInputBuilder) Node(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node) ArrayList(java.util.ArrayList) Metadata(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.Metadata) PacketReceivedBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.PacketReceivedBuilder) IpPrefix(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix) NodeRef(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef) TransmitPacketInput(org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.TransmitPacketInput) NodeId(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId) BigInteger(java.math.BigInteger) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) NodeKey(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey) MatchBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.packet.received.MatchBuilder) Ipv6Address(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address) Test(org.junit.Test)

Example 3 with Ipv6Address

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address in project netvirt by opendaylight.

the class Ipv6ServiceUtilsTest method testgetIpv6MulticastMacAddress.

/**
 *  Test getIpv6MulticastMacAddress with different IPv6Address values.
 */
@Test
public void testgetIpv6MulticastMacAddress() {
    Ipv6Address ipv6Address = new Ipv6Address(IPv6_ADDR_1);
    MacAddress expectedMacAddress = new MacAddress("33:33:fe:4e:18:0c");
    assertEquals(expectedMacAddress, Ipv6ServiceUtils.getIpv6MulticastMacAddress(ipv6Address));
    ipv6Address = new Ipv6Address(IPv6_ADDR_2);
    expectedMacAddress = new MacAddress("33:33:fe:4e:18:c0");
    assertEquals(expectedMacAddress, Ipv6ServiceUtils.getIpv6MulticastMacAddress(ipv6Address));
    ipv6Address = new Ipv6Address(IPv6_ADDR_4);
    expectedMacAddress = new MacAddress("33:33:fe:0f:00:6b");
    assertEquals(expectedMacAddress, Ipv6ServiceUtils.getIpv6MulticastMacAddress(ipv6Address));
}
Also used : MacAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress) Ipv6Address(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address) Test(org.junit.Test)

Example 4 with Ipv6Address

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address in project netvirt by opendaylight.

the class Ipv6ServiceUtilsTest method testgetIpv6SolicitedNodeMcastAddress.

/**
 *  Test getIpv6SolicitedNodeMcastAddress with different IPv6Address values.
 */
@Test
public void testgetIpv6SolicitedNodeMcastAddress() {
    Ipv6Address ipv6Address = new Ipv6Address(IPv6_ADDR_1);
    Ipv6Address expectedSolicitedNodeAddr = new Ipv6Address("ff02:0:0:0:0:1:ff4e:180c");
    assertEquals(expectedSolicitedNodeAddr, Ipv6ServiceUtils.getIpv6SolicitedNodeMcastAddress(ipv6Address));
    ipv6Address = new Ipv6Address(IPv6_ADDR_2);
    expectedSolicitedNodeAddr = new Ipv6Address("ff02:0:0:0:0:1:ff4e:18c0");
    assertEquals(expectedSolicitedNodeAddr, Ipv6ServiceUtils.getIpv6SolicitedNodeMcastAddress(ipv6Address));
    ipv6Address = new Ipv6Address(IPv6_ADDR_4);
    expectedSolicitedNodeAddr = new Ipv6Address("ff02:0:0:0:0:1:ff0f:6b");
    assertEquals(expectedSolicitedNodeAddr, Ipv6ServiceUtils.getIpv6SolicitedNodeMcastAddress(ipv6Address));
}
Also used : Ipv6Address(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address) Test(org.junit.Test)

Example 5 with Ipv6Address

use of org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address in project netvirt by opendaylight.

the class Ipv6ServiceUtilsTest method testgetIpv6LinkLocalAddressFromMac.

/**
 *  Test getIpv6LinkLocalAddressFromMac with different MACAddress values.
 */
@Test
public void testgetIpv6LinkLocalAddressFromMac() {
    MacAddress mac = new MacAddress("fa:16:3e:4e:18:0c");
    Ipv6Address expectedLinkLocalAddress = new Ipv6Address(IPv6_ADDR_1);
    assertEquals(expectedLinkLocalAddress, Ipv6ServiceUtils.getIpv6LinkLocalAddressFromMac(mac));
    mac = new MacAddress("fa:16:3e:4e:18:c0");
    expectedLinkLocalAddress = new Ipv6Address(IPv6_ADDR_2);
    assertEquals(expectedLinkLocalAddress, Ipv6ServiceUtils.getIpv6LinkLocalAddressFromMac(mac));
    mac = new MacAddress("0a:16:03:04:08:0c");
    expectedLinkLocalAddress = new Ipv6Address(IPv6_ADDR_3);
    assertEquals(expectedLinkLocalAddress, Ipv6ServiceUtils.getIpv6LinkLocalAddressFromMac(mac));
    mac = new MacAddress("f4:00:00:0f:00:6b");
    expectedLinkLocalAddress = new Ipv6Address(IPv6_ADDR_4);
    assertEquals(expectedLinkLocalAddress, Ipv6ServiceUtils.getIpv6LinkLocalAddressFromMac(mac));
    mac = new MacAddress("50:7B:9D:78:54:F3");
    expectedLinkLocalAddress = new Ipv6Address(IPv6_ADDR_5);
    assertEquals(expectedLinkLocalAddress, Ipv6ServiceUtils.getIpv6LinkLocalAddressFromMac(mac));
}
Also used : MacAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress) Ipv6Address(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address) Test(org.junit.Test)

Aggregations

Ipv6Address (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Address)83 Test (org.junit.Test)67 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)23 ByteBuf (io.netty.buffer.ByteBuf)21 ArrayList (java.util.ArrayList)21 IPv6Address (com.googlecode.ipv6.IPv6Address)18 MacAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress)17 BigInteger (java.math.BigInteger)16 Ipv6Prefix (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv6Prefix)16 MatchEntry (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry)15 Ipv4Address (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address)14 MatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder)13 Ipv6MatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.Ipv6MatchBuilder)12 MatchEntryBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntryBuilder)12 Ipv6SrcCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Ipv6SrcCaseBuilder)11 Ipv6SrcBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.ipv6.src._case.Ipv6SrcBuilder)11 Ipv6DstCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.Ipv6DstCaseBuilder)9 Ipv6DstBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entry.value.grouping.match.entry.value.ipv6.dst._case.Ipv6DstBuilder)9 Match (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.grouping.Match)9 MatchBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.grouping.MatchBuilder)9