Search in sources :

Example 86 with IpPrefix

use of org.onlab.packet.IpPrefix in project onos by opennetworkinglab.

the class NetworkAddress method valueOf.

/**
 * Converts a CIDR notation string into a network address.
 *
 * @param cidr cidr
 * @return network address
 * @throws IllegalArgumentException if the cidr is not valid
 */
public static NetworkAddress valueOf(String cidr) {
    checkArgument(cidr.contains("/"));
    IpAddress ipAddress = IpAddress.valueOf(cidr.split("/")[0]);
    IpPrefix ipPrefix = IpPrefix.valueOf(cidr);
    return new NetworkAddress(ipAddress, ipPrefix);
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) IpAddress(org.onlab.packet.IpAddress)

Example 87 with IpPrefix

use of org.onlab.packet.IpPrefix in project onos by opennetworkinglab.

the class IntReportConfig method watchSubnets.

/**
 * Gets subnets to be watched.
 *
 * @return subnets to be watched
 */
public Set<IpPrefix> watchSubnets() {
    if (object.hasNonNull(WATCH_SUBNETS) && object.path(WATCH_SUBNETS).isArray()) {
        Set<IpPrefix> subnets = Sets.newHashSet();
        ArrayNode subnetArray = (ArrayNode) object.path(WATCH_SUBNETS);
        subnetArray.forEach(subnetNode -> {
            subnets.add(IpPrefix.valueOf(subnetNode.asText()));
        });
        return subnets;
    } else {
        return Collections.EMPTY_SET;
    }
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 88 with IpPrefix

use of org.onlab.packet.IpPrefix in project onos by opennetworkinglab.

the class InterfaceIpAddress method valueOf.

/**
 * Converts a CIDR string literal to an interface IP address.
 * E.g. 10.0.0.1/24
 *
 * @param value an IP address value in string form
 * @return an interface IP address
 * @throws IllegalArgumentException if the argument is invalid
 */
public static InterfaceIpAddress valueOf(String value) {
    String[] splits = value.split("/");
    checkArgument(splits.length == 2, "Invalid IP address and prefix length format");
    // NOTE: IpPrefix will mask-out the bits after the prefix length.
    IpPrefix subnet = IpPrefix.valueOf(value);
    IpAddress addr = IpAddress.valueOf(splits[0]);
    return new InterfaceIpAddress(addr, subnet);
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) IpAddress(org.onlab.packet.IpAddress)

Example 89 with IpPrefix

use of org.onlab.packet.IpPrefix in project onos by opennetworkinglab.

the class DefaultTrafficSelectorTest method testCriteriaCreation.

/**
 * Tests the builder functions that add specific criteria.
 */
@Test
public void testCriteriaCreation() {
    TrafficSelector selector;
    final long longValue = 0x12345678;
    final int intValue = 22;
    final short shortValue = 33;
    final byte byteValue = 44;
    final byte dscpValue = 0xf;
    final byte ecnValue = 3;
    final MacAddress macValue = MacAddress.valueOf("11:22:33:44:55:66");
    final IpPrefix ipPrefixValue = IpPrefix.valueOf("192.168.1.0/24");
    final IpPrefix ipv6PrefixValue = IpPrefix.valueOf("fe80::1/64");
    final Ip6Address ipv6AddressValue = Ip6Address.valueOf("fe80::1");
    selector = DefaultTrafficSelector.builder().matchInPort(PortNumber.portNumber(11)).build();
    assertThat(selector, hasCriterionWithType(Type.IN_PORT));
    selector = DefaultTrafficSelector.builder().matchInPhyPort(PortNumber.portNumber(11)).build();
    assertThat(selector, hasCriterionWithType(Type.IN_PHY_PORT));
    selector = DefaultTrafficSelector.builder().matchMetadata(longValue).build();
    assertThat(selector, hasCriterionWithType(Type.METADATA));
    selector = DefaultTrafficSelector.builder().matchEthDst(macValue).build();
    assertThat(selector, hasCriterionWithType(Type.ETH_DST));
    selector = DefaultTrafficSelector.builder().matchEthSrc(macValue).build();
    assertThat(selector, hasCriterionWithType(Type.ETH_SRC));
    selector = DefaultTrafficSelector.builder().matchEthType(shortValue).build();
    assertThat(selector, hasCriterionWithType(Type.ETH_TYPE));
    selector = DefaultTrafficSelector.builder().matchVlanId(VlanId.vlanId(shortValue)).build();
    assertThat(selector, hasCriterionWithType(Type.VLAN_VID));
    selector = DefaultTrafficSelector.builder().matchVlanPcp(byteValue).build();
    assertThat(selector, hasCriterionWithType(Type.VLAN_PCP));
    selector = DefaultTrafficSelector.builder().matchIPDscp(dscpValue).build();
    assertThat(selector, hasCriterionWithType(Type.IP_DSCP));
    selector = DefaultTrafficSelector.builder().matchIPEcn(ecnValue).build();
    assertThat(selector, hasCriterionWithType(Type.IP_ECN));
    selector = DefaultTrafficSelector.builder().matchIPProtocol(byteValue).build();
    assertThat(selector, hasCriterionWithType(Type.IP_PROTO));
    selector = DefaultTrafficSelector.builder().matchIPSrc(ipPrefixValue).build();
    assertThat(selector, hasCriterionWithType(Type.IPV4_SRC));
    selector = DefaultTrafficSelector.builder().matchIPDst(ipPrefixValue).build();
    assertThat(selector, hasCriterionWithType(Type.IPV4_DST));
    selector = DefaultTrafficSelector.builder().matchTcpSrc(TpPort.tpPort(intValue)).build();
    assertThat(selector, hasCriterionWithType(Type.TCP_SRC));
    selector = DefaultTrafficSelector.builder().matchTcpDst(TpPort.tpPort(intValue)).build();
    assertThat(selector, hasCriterionWithType(Type.TCP_DST));
    selector = DefaultTrafficSelector.builder().matchUdpSrc(TpPort.tpPort(intValue)).build();
    assertThat(selector, hasCriterionWithType(Type.UDP_SRC));
    selector = DefaultTrafficSelector.builder().matchUdpDst(TpPort.tpPort(intValue)).build();
    assertThat(selector, hasCriterionWithType(Type.UDP_DST));
    selector = DefaultTrafficSelector.builder().matchSctpSrc(TpPort.tpPort(intValue)).build();
    assertThat(selector, hasCriterionWithType(Type.SCTP_SRC));
    selector = DefaultTrafficSelector.builder().matchSctpDst(TpPort.tpPort(intValue)).build();
    assertThat(selector, hasCriterionWithType(Type.SCTP_DST));
    selector = DefaultTrafficSelector.builder().matchIcmpType(byteValue).build();
    assertThat(selector, hasCriterionWithType(Type.ICMPV4_TYPE));
    selector = DefaultTrafficSelector.builder().matchIcmpCode(byteValue).build();
    assertThat(selector, hasCriterionWithType(Type.ICMPV4_CODE));
    selector = DefaultTrafficSelector.builder().matchIPv6Src(ipv6PrefixValue).build();
    assertThat(selector, hasCriterionWithType(Type.IPV6_SRC));
    selector = DefaultTrafficSelector.builder().matchIPv6Dst(ipv6PrefixValue).build();
    assertThat(selector, hasCriterionWithType(Type.IPV6_DST));
    selector = DefaultTrafficSelector.builder().matchIPv6FlowLabel(intValue).build();
    assertThat(selector, hasCriterionWithType(Type.IPV6_FLABEL));
    selector = DefaultTrafficSelector.builder().matchIcmpv6Type(byteValue).build();
    assertThat(selector, hasCriterionWithType(Type.ICMPV6_TYPE));
    selector = DefaultTrafficSelector.builder().matchIPv6NDTargetAddress(ipv6AddressValue).build();
    assertThat(selector, hasCriterionWithType(Type.IPV6_ND_TARGET));
    selector = DefaultTrafficSelector.builder().matchIPv6NDSourceLinkLayerAddress(macValue).build();
    assertThat(selector, hasCriterionWithType(Type.IPV6_ND_SLL));
    selector = DefaultTrafficSelector.builder().matchIPv6NDTargetLinkLayerAddress(macValue).build();
    assertThat(selector, hasCriterionWithType(Type.IPV6_ND_TLL));
    selector = DefaultTrafficSelector.builder().matchMplsLabel(MplsLabel.mplsLabel(3)).build();
    assertThat(selector, hasCriterionWithType(Type.MPLS_LABEL));
    selector = DefaultTrafficSelector.builder().matchIPv6ExthdrFlags(Criterion.IPv6ExthdrFlags.NONEXT.getValue()).build();
    assertThat(selector, hasCriterionWithType(Type.IPV6_EXTHDR));
    selector = DefaultTrafficSelector.builder().add(Criteria.matchLambda(new OchSignal(GridType.DWDM, ChannelSpacing.CHL_100GHZ, 1, 1))).build();
    assertThat(selector, hasCriterionWithType(Type.OCH_SIGID));
    selector = DefaultTrafficSelector.builder().matchEthDst(macValue).extension(new MockExtensionSelector(1), DeviceId.NONE).extension(new MockExtensionSelector(2), DeviceId.NONE).build();
    assertThat(selector.criteria().size(), is(equalTo(3)));
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) Ip6Address(org.onlab.packet.Ip6Address) OchSignal(org.onosproject.net.OchSignal) MacAddress(org.onlab.packet.MacAddress) Test(org.junit.Test)

Example 90 with IpPrefix

use of org.onlab.packet.IpPrefix in project onos by opennetworkinglab.

the class PiCriterionTranslatorsTest method testIpCriterion.

@Test
public void testIpCriterion() throws Exception {
    IpPrefix prefix1 = IpPrefix.valueOf(random.nextInt(), random.nextInt(32));
    int bitWidth = prefix1.address().toOctets().length * 8;
    IPCriterion criterion = (IPCriterion) Criteria.matchIPDst(prefix1);
    PiLpmFieldMatch lpmMatch = (PiLpmFieldMatch) translateCriterion(criterion, fieldId, LPM, bitWidth);
    assertThat(lpmMatch.value().asArray(), is(criterion.ip().address().toOctets()));
    assertThat(lpmMatch.prefixLength(), is(criterion.ip().prefixLength()));
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) IPCriterion(org.onosproject.net.flow.criteria.IPCriterion) PiLpmFieldMatch(org.onosproject.net.pi.runtime.PiLpmFieldMatch) Test(org.junit.Test)

Aggregations

IpPrefix (org.onlab.packet.IpPrefix)107 Test (org.junit.Test)37 IpAddress (org.onlab.packet.IpAddress)29 LinkedList (java.util.LinkedList)24 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)22 BgpHeader (org.onosproject.bgpio.types.BgpHeader)22 BgpPathAttributes (org.onosproject.bgpio.protocol.ver4.BgpPathAttributes)21 AsPath (org.onosproject.bgpio.types.AsPath)21 BgpValueType (org.onosproject.bgpio.types.BgpValueType)21 Origin (org.onosproject.bgpio.types.Origin)21 OriginType (org.onosproject.bgpio.types.Origin.OriginType)21 Med (org.onosproject.bgpio.types.Med)20 TrafficSelector (org.onosproject.net.flow.TrafficSelector)20 ProtocolType (org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4.ProtocolType)19 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)19 MpReachNlri (org.onosproject.bgpio.types.MpReachNlri)18 LinkStateAttributes (org.onosproject.bgpio.types.LinkStateAttributes)16 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)14 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)14 MacAddress (org.onlab.packet.MacAddress)12