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);
}
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;
}
}
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);
}
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)));
}
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()));
}
Aggregations