Search in sources :

Example 21 with IpPrefixOrAddress

use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.types.rev160517.IpPrefixOrAddress in project netvirt by opendaylight.

the class AclServiceUtils method getInetAddress.

private static InetAddress getInetAddress(IpPrefixOrAddress ipPrefixOrAddress) {
    InetAddress inetAddress = null;
    String addr = null;
    IpPrefix ipPrefix = ipPrefixOrAddress.getIpPrefix();
    if (ipPrefix != null) {
        addr = String.valueOf(ipPrefix.getValue()).split("/")[0];
    } else {
        IpAddress ipAddress = ipPrefixOrAddress.getIpAddress();
        if (ipAddress == null) {
            LOG.error("Invalid address : {}", ipPrefixOrAddress);
            return null;
        } else {
            addr = String.valueOf(ipAddress.getValue());
        }
    }
    try {
        inetAddress = InetAddress.getByName(addr);
    } catch (UnknownHostException e) {
        LOG.error("Invalid address : {}", addr, e);
        return null;
    }
    return inetAddress;
}
Also used : IpPrefix(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix) UnknownHostException(java.net.UnknownHostException) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress) InetAddress(java.net.InetAddress)

Example 22 with IpPrefixOrAddress

use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.types.rev160517.IpPrefixOrAddress in project netvirt by opendaylight.

the class AclServiceUtils method isIPv4Address.

public static boolean isIPv4Address(AllowedAddressPairs aap) {
    IpPrefixOrAddress ipPrefixOrAddress = aap.getIpAddress();
    IpPrefix ipPrefix = ipPrefixOrAddress.getIpPrefix();
    if (ipPrefix != null) {
        if (ipPrefix.getIpv4Prefix() != null) {
            return true;
        }
    } else {
        IpAddress ipAddress = ipPrefixOrAddress.getIpAddress();
        if (ipAddress != null && ipAddress.getIpv4Address() != null) {
            return true;
        }
    }
    return false;
}
Also used : IpPrefix(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix) IpPrefixOrAddress(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.IpPrefixOrAddress) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)

Example 23 with IpPrefixOrAddress

use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.types.rev160517.IpPrefixOrAddress in project netvirt by opendaylight.

the class AclServiceUtils method doesIpv4AddressExists.

/**
 * Does IPv4 address exists in the list of allowed address pair.
 *
 * @param aaps the allowed address pairs
 * @return true, if successful
 */
public static boolean doesIpv4AddressExists(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.getIpv4Prefix() != null) {
                return true;
            }
        } else {
            IpAddress ipAddress = ipPrefixOrAddress.getIpAddress();
            if (ipAddress != null && ipAddress.getIpv4Address() != null) {
                return true;
            }
        }
    }
    return false;
}
Also used : IpPrefix(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix) IpPrefixOrAddress(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.IpPrefixOrAddress) AllowedAddressPairs(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.interfaces._interface.AllowedAddressPairs) IpAddress(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)

Example 24 with IpPrefixOrAddress

use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.types.rev160517.IpPrefixOrAddress in project netvirt by opendaylight.

the class AclServiceTestBase method newInterfaceWithDstAllPorts.

@Test
public void newInterfaceWithDstAllPorts() throws Exception {
    LOG.info("newInterfaceWithDstAllPorts - start");
    newAllowedAddressPair(PORT_1, Collections.singletonList(SG_UUID_1), Collections.singletonList(AAP_PORT_1));
    dataBrokerUtil.put(new IdentifiedSubnetIpPrefixBuilder().interfaceName(PORT_1).addAllIpPrefixOrAddress(Collections.singletonList(new IpPrefixOrAddress(SUBNET_IP_PREFIX_1.toCharArray()))));
    // Given
    Matches matches = newMatch(AclConstants.SOURCE_LOWER_PORT_UNSPECIFIED, AclConstants.SOURCE_UPPER_PORT_UNSPECIFIED, 1, 65535, AclConstants.SOURCE_REMOTE_IP_PREFIX_UNSPECIFIED, AclConstants.DEST_REMOTE_IP_PREFIX_SPECIFIED, (short) NwConstants.IP_PROT_TCP);
    dataBrokerUtil.put(new IdentifiedAceBuilder().sgUuid(SG_UUID_1).newRuleName(SR_UUID_1_1).newMatches(matches).newDirection(DirectionEgress.class).build());
    matches = newMatch(AclConstants.SOURCE_LOWER_PORT_UNSPECIFIED, AclConstants.SOURCE_UPPER_PORT_UNSPECIFIED, 1, 65535, AclConstants.SOURCE_REMOTE_IP_PREFIX_SPECIFIED, AclConstants.DEST_REMOTE_IP_PREFIX_UNSPECIFIED, (short) NwConstants.IP_PROT_UDP);
    dataBrokerUtil.put(new IdentifiedAceBuilder().sgUuid(SG_UUID_1).newRuleName(SR_UUID_1_2).newMatches(matches).newDirection(DirectionIngress.class).build());
    // When
    putNewStateInterface(dataBroker, PORT_1, PORT_MAC_1);
    asyncEventsWaiter.awaitEventsConsumption();
    // Then
    newInterfaceWithDstAllPortsCheck();
    LOG.info("newInterfaceWithDstAllPorts - end");
}
Also used : Matches(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.Matches) IpPrefixOrAddress(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.IpPrefixOrAddress) Test(org.junit.Test)

Example 25 with IpPrefixOrAddress

use of org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.types.rev160517.IpPrefixOrAddress in project netvirt by opendaylight.

the class AclServiceTestBase method newInterfaceWithEtherTypeAcl.

@Test
public void newInterfaceWithEtherTypeAcl() throws Exception {
    LOG.info("newInterfaceWithEtherTypeAcl - start");
    newAllowedAddressPair(PORT_1, Collections.singletonList(SG_UUID_1), Collections.singletonList(AAP_PORT_1));
    newAllowedAddressPair(PORT_2, Collections.singletonList(SG_UUID_1), Collections.singletonList(AAP_PORT_2));
    dataBrokerUtil.put(new IdentifiedSubnetIpPrefixBuilder().interfaceName(PORT_1).addAllIpPrefixOrAddress(Collections.singletonList(new IpPrefixOrAddress(SUBNET_IP_PREFIX_1.toCharArray()))));
    dataBrokerUtil.put(new IdentifiedSubnetIpPrefixBuilder().interfaceName(PORT_2).addAllIpPrefixOrAddress(Collections.singletonList(new IpPrefixOrAddress(SUBNET_IP_PREFIX_1.toCharArray()))));
    Matches matches = newMatch(AclConstants.SOURCE_LOWER_PORT_UNSPECIFIED, AclConstants.SOURCE_UPPER_PORT_UNSPECIFIED, AclConstants.DEST_LOWER_PORT_UNSPECIFIED, AclConstants.DEST_UPPER_PORT_UNSPECIFIED, AclConstants.SOURCE_REMOTE_IP_PREFIX_UNSPECIFIED, AclConstants.DEST_REMOTE_IP_PREFIX_SPECIFIED, (short) -1);
    dataBrokerUtil.put(new IdentifiedAceBuilder().sgUuid(SG_UUID_1).newRuleName(SR_UUID_1_1).newMatches(matches).newDirection(DirectionEgress.class).build());
    matches = newMatch(AclConstants.SOURCE_LOWER_PORT_UNSPECIFIED, AclConstants.SOURCE_UPPER_PORT_UNSPECIFIED, AclConstants.DEST_LOWER_PORT_UNSPECIFIED, AclConstants.DEST_UPPER_PORT_UNSPECIFIED, AclConstants.SOURCE_REMOTE_IP_PREFIX_SPECIFIED, AclConstants.DEST_REMOTE_IP_PREFIX_UNSPECIFIED, (short) -1);
    dataBrokerUtil.put(new IdentifiedAceBuilder().sgUuid(SG_UUID_1).newRuleName(SR_UUID_1_2).newMatches(matches).newDirection(DirectionIngress.class).newRemoteGroupId(new Uuid(SG_UUID_1)).build());
    // When
    putNewStateInterface(dataBroker, PORT_1, PORT_MAC_1);
    putNewStateInterface(dataBroker, PORT_2, PORT_MAC_2);
    asyncEventsWaiter.awaitEventsConsumption();
    // Then
    newInterfaceWithEtherTypeAclCheck();
    LOG.info("newInterfaceWithEtherTypeAcl - end");
}
Also used : Uuid(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid) Matches(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.Matches) IpPrefixOrAddress(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.IpPrefixOrAddress) DirectionIngress(org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.DirectionIngress) Test(org.junit.Test)

Aggregations

IpPrefixOrAddress (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.IpPrefixOrAddress)26 ArrayList (java.util.ArrayList)12 Test (org.junit.Test)12 MatchInfoBase (org.opendaylight.genius.mdsalutil.MatchInfoBase)10 Matches (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.access.control.list.rev160218.access.lists.acl.access.list.entries.ace.Matches)8 InstructionInfo (org.opendaylight.genius.mdsalutil.InstructionInfo)7 IpAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpAddress)7 IpPrefix (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.IpPrefix)7 MacAddress (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress)7 Uuid (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.Uuid)7 AllowedAddressPairs (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.interfaces._interface.AllowedAddressPairs)7 InstructionGotoTable (org.opendaylight.genius.mdsalutil.instructions.InstructionGotoTable)4 ActionInfo (org.opendaylight.genius.mdsalutil.ActionInfo)3 ActionNxConntrack (org.opendaylight.genius.mdsalutil.actions.ActionNxConntrack)3 NxCtAction (org.opendaylight.genius.mdsalutil.actions.ActionNxConntrack.NxCtAction)3 InstructionApplyActions (org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions)3 MatchMetadata (org.opendaylight.genius.mdsalutil.matches.MatchMetadata)3 Ipv4Prefix (org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix)3 DirectionIngress (org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.aclservice.rev160608.DirectionIngress)3 BigInteger (java.math.BigInteger)2