Ayaka Koshibe

renamed IpAddress to IpPrefix

Change-Id: I35990622e5b1c29ab6f6a0a0227088cd5d6c7294
Showing 24 changed files with 128 additions and 128 deletions
......@@ -16,7 +16,7 @@ import org.onlab.onos.net.topology.Topology;
import org.onlab.onos.net.topology.TopologyGraph;
import org.onlab.onos.net.topology.TopologyService;
import org.onlab.onos.net.topology.TopologyVertex;
import org.onlab.packet.IpAddress;
import org.onlab.packet.IpPrefix;
import org.onlab.rest.BaseResource;
import javax.ws.rs.GET;
......@@ -74,8 +74,8 @@ public class TopologyResource extends BaseResource {
// Merge the exterior and interior vertexes and inject host links as
// the exterior edges.
for (Host host : hostService.getHosts()) {
Set<IpAddress> ipAddresses = host.ipAddresses();
IpAddress ipAddress = ipAddresses.isEmpty() ? null : ipAddresses.iterator().next();
Set<IpPrefix> ipAddresses = host.ipAddresses();
IpPrefix ipAddress = ipAddresses.isEmpty() ? null : ipAddresses.iterator().next();
String label = ipAddress != null ? ipAddress.toString() : host.mac().toString();
vertexesNode.add(json(mapper, host.id(), 3, label, true));
edgesNode.add(json(mapper, 1, host.location(), new ConnectPoint(host.id(), portNumber(-1))));
......
package org.onlab.onos.cluster;
import org.onlab.packet.IpAddress;
import org.onlab.packet.IpPrefix;
/**
* Represents a controller instance as a member in a cluster.
......@@ -33,6 +33,6 @@ public interface ControllerInstance {
*
* @return IP address
*/
IpAddress ip();
IpPrefix ip();
}
......
......@@ -8,7 +8,7 @@ import java.util.Objects;
import java.util.Set;
import org.onlab.onos.net.provider.ProviderId;
import org.onlab.packet.IpAddress;
import org.onlab.packet.IpPrefix;
import org.onlab.packet.MacAddress;
import org.onlab.packet.VlanId;
......@@ -20,15 +20,15 @@ public class DefaultHost extends AbstractElement implements Host {
private final MacAddress mac;
private final VlanId vlan;
private final HostLocation location;
private final Set<IpAddress> ips;
private final Set<IpPrefix> ips;
public DefaultHost(ProviderId providerId, HostId id, MacAddress mac,
VlanId vlan, HostLocation loc, Set<IpAddress> ips) {
VlanId vlan, HostLocation loc, Set<IpPrefix> ips) {
super(providerId, id);
this.mac = mac;
this.vlan = vlan;
this.location = loc;
this.ips = new HashSet<IpAddress>(ips);
this.ips = new HashSet<IpPrefix>(ips);
}
@Override
......@@ -42,7 +42,7 @@ public class DefaultHost extends AbstractElement implements Host {
}
@Override
public Set<IpAddress> ipAddresses() {
public Set<IpPrefix> ipAddresses() {
return Collections.unmodifiableSet(ips);
}
......
package org.onlab.onos.net;
import org.onlab.packet.IpAddress;
import org.onlab.packet.IpPrefix;
import org.onlab.packet.MacAddress;
import org.onlab.packet.VlanId;
......@@ -38,7 +38,7 @@ public interface Host extends Element {
*
* @return set of IP addresses; empty if no IP address is bound
*/
Set<IpAddress> ipAddresses();
Set<IpPrefix> ipAddresses();
/**
* Returns the most recent host location where the host attaches to the
......
......@@ -2,7 +2,7 @@ package org.onlab.onos.net.flow.criteria;
import org.onlab.onos.net.PortNumber;
import org.onlab.onos.net.flow.criteria.Criterion.Type;
import org.onlab.packet.IpAddress;
import org.onlab.packet.IpPrefix;
import org.onlab.packet.MacAddress;
import org.onlab.packet.VlanId;
......@@ -95,7 +95,7 @@ public final class Criteria {
* @param ip ip src value
* @return match criterion
*/
public static Criterion matchIPSrc(IpAddress ip) {
public static Criterion matchIPSrc(IpPrefix ip) {
return new IPCriterion(ip, Type.IPV4_SRC);
}
......@@ -105,7 +105,7 @@ public final class Criteria {
* @param ip ip src value
* @return match criterion
*/
public static Criterion matchIPDst(IpAddress ip) {
public static Criterion matchIPDst(IpPrefix ip) {
return new IPCriterion(ip, Type.IPV4_DST);
}
......@@ -173,10 +173,10 @@ public final class Criteria {
public static final class IPCriterion implements Criterion {
private final IpAddress ip;
private final IpPrefix ip;
private final Type type;
public IPCriterion(IpAddress ip, Type type) {
public IPCriterion(IpPrefix ip, Type type) {
this.ip = ip;
this.type = type;
}
......@@ -186,7 +186,7 @@ public final class Criteria {
return this.type;
}
public IpAddress ip() {
public IpPrefix ip() {
return this.ip;
}
......
......@@ -7,7 +7,7 @@ import org.onlab.onos.net.flow.instructions.L2ModificationInstruction.L2SubType;
import org.onlab.onos.net.flow.instructions.L2ModificationInstruction.ModEtherInstruction;
import org.onlab.onos.net.flow.instructions.L3ModificationInstruction.L3SubType;
import org.onlab.onos.net.flow.instructions.L3ModificationInstruction.ModIPInstruction;
import org.onlab.packet.IpAddress;
import org.onlab.packet.IpPrefix;
import org.onlab.packet.MacAddress;
import org.onlab.packet.VlanId;
......@@ -85,7 +85,7 @@ public final class Instructions {
* @param addr the ip address to modify to.
* @return a L3 modification
*/
public static L3ModificationInstruction modL3Src(IpAddress addr) {
public static L3ModificationInstruction modL3Src(IpPrefix addr) {
checkNotNull(addr, "Src l3 address cannot be null");
return new ModIPInstruction(L3SubType.L3_SRC, addr);
}
......@@ -95,7 +95,7 @@ public final class Instructions {
* @param addr the ip address to modify to.
* @return a L3 modification
*/
public static L3ModificationInstruction modL3Dst(IpAddress addr) {
public static L3ModificationInstruction modL3Dst(IpPrefix addr) {
checkNotNull(addr, "Dst l3 address cannot be null");
return new ModIPInstruction(L3SubType.L3_DST, addr);
}
......
package org.onlab.onos.net.flow.instructions;
import org.onlab.packet.IpAddress;
import org.onlab.packet.IpPrefix;
/**
* Abstraction of a single traffic treatment step.
......@@ -41,9 +41,9 @@ public abstract class L3ModificationInstruction implements Instruction {
public static final class ModIPInstruction extends L3ModificationInstruction {
private final L3SubType subtype;
private final IpAddress ip;
private final IpPrefix ip;
public ModIPInstruction(L3SubType subType, IpAddress addr) {
public ModIPInstruction(L3SubType subType, IpPrefix addr) {
this.subtype = subType;
this.ip = addr;
......@@ -54,7 +54,7 @@ public abstract class L3ModificationInstruction implements Instruction {
return this.subtype;
}
public IpAddress ip() {
public IpPrefix ip() {
return this.ip;
}
......
......@@ -6,7 +6,7 @@ import java.util.HashSet;
import java.util.Set;
import org.onlab.onos.net.HostLocation;
import org.onlab.packet.IpAddress;
import org.onlab.packet.IpPrefix;
import org.onlab.packet.MacAddress;
import org.onlab.packet.VlanId;
......@@ -17,22 +17,22 @@ public class DefaultHostDescription implements HostDescription {
private final MacAddress mac;
private final VlanId vlan;
private final HostLocation location;
private final Set<IpAddress> ips;
private final Set<IpPrefix> ips;
public DefaultHostDescription(MacAddress mac, VlanId vlan,
HostLocation loc) {
this.mac = mac;
this.vlan = vlan;
this.location = loc;
this.ips = new HashSet<IpAddress>();
this.ips = new HashSet<IpPrefix>();
}
public DefaultHostDescription(MacAddress mac, VlanId vlan,
HostLocation loc, Set<IpAddress> ips) {
HostLocation loc, Set<IpPrefix> ips) {
this.mac = mac;
this.vlan = vlan;
this.location = loc;
this.ips = new HashSet<IpAddress>(ips);
this.ips = new HashSet<IpPrefix>(ips);
}
@Override
......@@ -51,7 +51,7 @@ public class DefaultHostDescription implements HostDescription {
}
@Override
public Set<IpAddress> ipAddresses() {
public Set<IpPrefix> ipAddresses() {
return ImmutableSet.copyOf(ips);
}
......
......@@ -4,7 +4,7 @@ import java.util.Set;
import org.onlab.onos.net.Description;
import org.onlab.onos.net.HostLocation;
import org.onlab.packet.IpAddress;
import org.onlab.packet.IpPrefix;
import org.onlab.packet.MacAddress;
import org.onlab.packet.VlanId;
......@@ -39,6 +39,6 @@ public interface HostDescription extends Description {
*
* @return a set of IP addresses.
*/
Set<IpAddress> ipAddresses();
Set<IpPrefix> ipAddresses();
}
......
......@@ -4,7 +4,7 @@ import org.onlab.onos.net.ConnectPoint;
import org.onlab.onos.net.DeviceId;
import org.onlab.onos.net.Host;
import org.onlab.onos.net.HostId;
import org.onlab.packet.IpAddress;
import org.onlab.packet.IpPrefix;
import org.onlab.packet.MacAddress;
import org.onlab.packet.VlanId;
......@@ -59,7 +59,7 @@ public interface HostService {
* @param ip ip address
* @return set of hosts with the given IP
*/
Set<Host> getHostsByIp(IpAddress ip);
Set<Host> getHostsByIp(IpPrefix ip);
// TODO: consider adding Host getHostByIp(IpAddress ip, VlanId vlan);
......
......@@ -5,7 +5,7 @@ import org.onlab.onos.net.DeviceId;
import org.onlab.onos.net.Host;
import org.onlab.onos.net.HostId;
import org.onlab.onos.net.provider.ProviderId;
import org.onlab.packet.IpAddress;
import org.onlab.packet.IpPrefix;
import org.onlab.packet.MacAddress;
import org.onlab.packet.VlanId;
......@@ -81,7 +81,7 @@ public interface HostStore {
* @param ip ip address
* @return set of hosts with the given IP
*/
Set<Host> getHosts(IpAddress ip);
Set<Host> getHosts(IpPrefix ip);
/**
* Returns the set of hosts whose location falls on the given connection point.
......
......@@ -5,7 +5,7 @@ import static org.onlab.onos.net.DeviceId.deviceId;
import java.util.Set;
import org.onlab.onos.net.provider.ProviderId;
import org.onlab.packet.IpAddress;
import org.onlab.packet.IpPrefix;
import org.onlab.packet.MacAddress;
import org.onlab.packet.VlanId;
......@@ -24,9 +24,9 @@ public abstract class TestDeviceParams {
protected static final MacAddress MAC2 = MacAddress.valueOf("00:22:00:00:00:02");
protected static final VlanId VLAN1 = VlanId.vlanId((short) 11);
protected static final VlanId VLAN2 = VlanId.vlanId((short) 22);
protected static final IpAddress IP1 = IpAddress.valueOf("10.0.0.1");
protected static final IpAddress IP2 = IpAddress.valueOf("10.0.0.2");
protected static final IpAddress IP3 = IpAddress.valueOf("10.0.0.3");
protected static final IpPrefix IP1 = IpPrefix.valueOf("10.0.0.1");
protected static final IpPrefix IP2 = IpPrefix.valueOf("10.0.0.2");
protected static final IpPrefix IP3 = IpPrefix.valueOf("10.0.0.3");
protected static final PortNumber P1 = PortNumber.portNumber(100);
protected static final PortNumber P2 = PortNumber.portNumber(200);
......@@ -34,7 +34,7 @@ public abstract class TestDeviceParams {
protected static final HostId HID2 = HostId.hostId(MAC2, VLAN2);
protected static final HostLocation LOC1 = new HostLocation(DID1, P1, 123L);
protected static final HostLocation LOC2 = new HostLocation(DID2, P2, 123L);
protected static final Set<IpAddress> IPSET1 = Sets.newHashSet(IP1, IP2);
protected static final Set<IpAddress> IPSET2 = Sets.newHashSet(IP1, IP3);
protected static final Set<IpPrefix> IPSET1 = Sets.newHashSet(IP1, IP2);
protected static final Set<IpPrefix> IPSET2 = Sets.newHashSet(IP1, IP3);
}
......
......@@ -9,7 +9,7 @@ import org.junit.Test;
import org.onlab.onos.net.DeviceId;
import org.onlab.onos.net.HostLocation;
import org.onlab.onos.net.PortNumber;
import org.onlab.packet.IpAddress;
import org.onlab.packet.IpPrefix;
import org.onlab.packet.MacAddress;
import org.onlab.packet.VlanId;
......@@ -27,9 +27,9 @@ public class DefualtHostDecriptionTest {
PortNumber.portNumber(100),
123L
);
private static final Set<IpAddress> IPS = Sets.newHashSet(
IpAddress.valueOf("10.0.0.1"),
IpAddress.valueOf("10.0.0.2")
private static final Set<IpPrefix> IPS = Sets.newHashSet(
IpPrefix.valueOf("10.0.0.1"),
IpPrefix.valueOf("10.0.0.2")
);
@Test
......
......@@ -11,7 +11,7 @@ import org.onlab.onos.net.HostId;
import org.onlab.onos.net.HostLocation;
import org.onlab.onos.net.PortNumber;
import org.onlab.onos.net.provider.ProviderId;
import org.onlab.packet.IpAddress;
import org.onlab.packet.IpPrefix;
import org.onlab.packet.MacAddress;
import org.onlab.packet.VlanId;
......@@ -27,9 +27,9 @@ public class HostEventTest extends AbstractEventTest {
PortNumber.portNumber(100),
123L
);
Set<IpAddress> ipset = Sets.newHashSet(
IpAddress.valueOf("10.0.0.1"),
IpAddress.valueOf("10.0.0.2")
Set<IpPrefix> ipset = Sets.newHashSet(
IpPrefix.valueOf("10.0.0.1"),
IpPrefix.valueOf("10.0.0.2")
);
HostId hid = HostId.hostId(mac, vlan);
......
......@@ -4,7 +4,7 @@ import org.onlab.onos.net.ConnectPoint;
import org.onlab.onos.net.DeviceId;
import org.onlab.onos.net.Host;
import org.onlab.onos.net.HostId;
import org.onlab.packet.IpAddress;
import org.onlab.packet.IpPrefix;
import org.onlab.packet.MacAddress;
import org.onlab.packet.VlanId;
......@@ -40,7 +40,7 @@ public class HostServiceAdapter implements HostService {
}
@Override
public Set<Host> getHostsByIp(IpAddress ip) {
public Set<Host> getHostsByIp(IpPrefix ip) {
return null;
}
......
......@@ -23,7 +23,7 @@ import org.onlab.onos.net.host.HostService;
import org.onlab.onos.net.host.HostStore;
import org.onlab.onos.net.provider.AbstractProviderRegistry;
import org.onlab.onos.net.provider.AbstractProviderService;
import org.onlab.packet.IpAddress;
import org.onlab.packet.IpPrefix;
import org.onlab.packet.MacAddress;
import org.onlab.packet.VlanId;
import org.slf4j.Logger;
......@@ -100,7 +100,7 @@ public class SimpleHostManager
}
@Override
public Set<Host> getHostsByIp(IpAddress ip) {
public Set<Host> getHostsByIp(IpPrefix ip) {
checkNotNull(ip, "IP address cannot be null");
return store.getHosts(ip);
}
......
......@@ -25,7 +25,7 @@ import org.onlab.onos.net.host.HostDescription;
import org.onlab.onos.net.host.HostEvent;
import org.onlab.onos.net.host.HostStore;
import org.onlab.onos.net.provider.ProviderId;
import org.onlab.packet.IpAddress;
import org.onlab.packet.IpPrefix;
import org.onlab.packet.MacAddress;
import org.onlab.packet.VlanId;
......@@ -166,7 +166,7 @@ public class SimpleHostStore implements HostStore {
}
@Override
public Set<Host> getHosts(IpAddress ip) {
public Set<Host> getHosts(IpPrefix ip) {
Set<Host> ipset = new HashSet<>();
for (Host h : hosts.values()) {
if (h.ipAddresses().contains(ip)) {
......
......@@ -28,7 +28,7 @@ import org.onlab.onos.net.host.HostProviderRegistry;
import org.onlab.onos.net.host.HostProviderService;
import org.onlab.onos.net.provider.AbstractProvider;
import org.onlab.onos.net.provider.ProviderId;
import org.onlab.packet.IpAddress;
import org.onlab.packet.IpPrefix;
import org.onlab.packet.MacAddress;
import org.onlab.packet.VlanId;
......@@ -51,10 +51,10 @@ public class SimpleHostManagerTest {
private static final HostId HID1 = HostId.hostId(MAC1, VLAN1);
private static final HostId HID2 = HostId.hostId(MAC2, VLAN1);
private static final IpAddress IP1 = IpAddress.valueOf("10.0.0.1");
private static final IpAddress IP2 = IpAddress.valueOf("10.0.0.2");
private static final Set<IpAddress> IPSET1 = Sets.newHashSet(IP1);
private static final Set<IpAddress> IPSET2 = Sets.newHashSet(IP2);
private static final IpPrefix IP1 = IpPrefix.valueOf("10.0.0.1");
private static final IpPrefix IP2 = IpPrefix.valueOf("10.0.0.2");
private static final Set<IpPrefix> IPSET1 = Sets.newHashSet(IP1);
private static final Set<IpPrefix> IPSET2 = Sets.newHashSet(IP2);
private static final DeviceId DID1 = DeviceId.deviceId("of:001");
private static final DeviceId DID2 = DeviceId.deviceId("of:002");
......@@ -98,7 +98,7 @@ public class SimpleHostManagerTest {
}
private void detect(HostId hid, MacAddress mac, VlanId vlan,
HostLocation loc, Set<IpAddress> ips) {
HostLocation loc, Set<IpPrefix> ips) {
HostDescription descr = new DefaultHostDescription(mac, vlan, loc, ips);
providerService.hostDetected(hid, descr);
assertNotNull("host should be found", mgr.getHost(hid));
......
......@@ -15,7 +15,7 @@ import org.onlab.onos.net.flow.TrafficTreatment;
import org.onlab.onos.net.flow.criteria.Criteria;
import org.onlab.onos.net.flow.instructions.Instructions;
import org.onlab.onos.openflow.controller.Dpid;
import org.onlab.packet.IpAddress;
import org.onlab.packet.IpPrefix;
import org.onlab.packet.MacAddress;
import org.onlab.packet.VlanId;
import org.projectfloodlight.openflow.protocol.OFFlowRemoved;
......@@ -120,20 +120,20 @@ public class FlowRuleBuilder {
OFActionSetNwDst nwdst = (OFActionSetNwDst) act;
IPv4Address di = nwdst.getNwAddr();
if (di.isCidrMask()) {
builder.add(Instructions.modL3Dst(IpAddress.valueOf(di.getInt(),
builder.add(Instructions.modL3Dst(IpPrefix.valueOf(di.getInt(),
di.asCidrMaskLength())));
} else {
builder.add(Instructions.modL3Dst(IpAddress.valueOf(di.getInt())));
builder.add(Instructions.modL3Dst(IpPrefix.valueOf(di.getInt())));
}
break;
case SET_NW_SRC:
OFActionSetNwSrc nwsrc = (OFActionSetNwSrc) act;
IPv4Address si = nwsrc.getNwAddr();
if (si.isCidrMask()) {
builder.add(Instructions.modL3Dst(IpAddress.valueOf(si.getInt(),
builder.add(Instructions.modL3Dst(IpPrefix.valueOf(si.getInt(),
si.asCidrMaskLength())));
} else {
builder.add(Instructions.modL3Dst(IpAddress.valueOf(si.getInt())));
builder.add(Instructions.modL3Dst(IpPrefix.valueOf(si.getInt())));
}
break;
case SET_TP_DST:
......@@ -190,21 +190,21 @@ public class FlowRuleBuilder {
break;
case IPV4_DST:
IPv4Address di = match.get(MatchField.IPV4_DST);
IpAddress dip;
IpPrefix dip;
if (di.isCidrMask()) {
dip = IpAddress.valueOf(di.getInt(), di.asCidrMaskLength());
dip = IpPrefix.valueOf(di.getInt(), di.asCidrMaskLength());
} else {
dip = IpAddress.valueOf(di.getInt());
dip = IpPrefix.valueOf(di.getInt());
}
builder.add(Criteria.matchIPDst(dip));
break;
case IPV4_SRC:
IPv4Address si = match.get(MatchField.IPV4_SRC);
IpAddress sip;
IpPrefix sip;
if (si.isCidrMask()) {
sip = IpAddress.valueOf(si.getInt(), si.asCidrMaskLength());
sip = IpPrefix.valueOf(si.getInt(), si.asCidrMaskLength());
} else {
sip = IpAddress.valueOf(si.getInt());
sip = IpPrefix.valueOf(si.getInt());
}
builder.add(Criteria.matchIPSrc(sip));
break;
......
......@@ -31,7 +31,7 @@ import org.onlab.onos.openflow.controller.OpenFlowPacketContext;
import org.onlab.onos.openflow.controller.PacketListener;
import org.onlab.packet.ARP;
import org.onlab.packet.Ethernet;
import org.onlab.packet.IpAddress;
import org.onlab.packet.IpPrefix;
import org.onlab.packet.VlanId;
import org.slf4j.Logger;
......@@ -110,7 +110,7 @@ public class OpenFlowHostProvider extends AbstractProvider implements HostProvid
HostId hid = HostId.hostId(eth.getSourceMAC(), vlan);
ARP arp = (ARP) eth.getPayload();
Set<IpAddress> ips = newHashSet(IpAddress.valueOf(arp.getSenderProtocolAddress()));
Set<IpPrefix> ips = newHashSet(IpPrefix.valueOf(arp.getSenderProtocolAddress()));
HostDescription hdescr =
new DefaultHostDescription(eth.getSourceMAC(), vlan, hloc, ips);
providerService.hostDetected(hid, hdescr);
......
......@@ -36,7 +36,7 @@ import org.onlab.onos.openflow.controller.PacketListener;
import org.onlab.onos.openflow.controller.RoleState;
import org.onlab.packet.ARP;
import org.onlab.packet.Ethernet;
import org.onlab.packet.IpAddress;
import org.onlab.packet.IpPrefix;
import org.projectfloodlight.openflow.protocol.OFFactory;
import org.projectfloodlight.openflow.protocol.OFMessage;
import org.projectfloodlight.openflow.protocol.OFPacketIn;
......@@ -113,10 +113,10 @@ public class OpenFlowPacketProviderTest {
MacAddress mac2 = MacAddress.of("00:00:00:22:00:02");
ARP arp = new ARP();
arp.setSenderProtocolAddress(IpAddress.ANY)
arp.setSenderProtocolAddress(IpPrefix.ANY)
.setSenderHardwareAddress(mac1.getBytes())
.setTargetHardwareAddress(mac2.getBytes())
.setTargetProtocolAddress(IpAddress.ANY)
.setTargetProtocolAddress(IpPrefix.ANY)
.setHardwareType((short) 0)
.setProtocolType((short) 0)
.setHardwareAddressLength((byte) 6)
......
......@@ -5,7 +5,7 @@ import java.util.Arrays;
/**
* A class representing an IPv4 address.
*/
public final class IpAddress {
public final class IpPrefix {
// TODO a comparator for netmasks? E.g. for sorting by prefix match order.
......@@ -31,13 +31,13 @@ public final class IpAddress {
protected byte[] octets;
protected int netmask;
private IpAddress(Version ver, byte[] octets, int netmask) {
private IpPrefix(Version ver, byte[] octets, int netmask) {
this.version = ver;
this.octets = Arrays.copyOf(octets, INET_LEN);
this.netmask = netmask;
}
private IpAddress(Version ver, byte[] octets) {
private IpPrefix(Version ver, byte[] octets) {
this.version = ver;
this.octets = Arrays.copyOf(octets, INET_LEN);
this.netmask = DEFAULT_MASK;
......@@ -49,8 +49,8 @@ public final class IpAddress {
* @param address a byte array
* @return an IP address
*/
public static IpAddress valueOf(byte [] address) {
return new IpAddress(Version.INET, address);
public static IpPrefix valueOf(byte [] address) {
return new IpPrefix(Version.INET, address);
}
/**
......@@ -60,8 +60,8 @@ public final class IpAddress {
* @param netmask the CIDR value subnet mask
* @return an IP address
*/
public static IpAddress valueOf(byte [] address, int netmask) {
return new IpAddress(Version.INET, address, netmask);
public static IpPrefix valueOf(byte [] address, int netmask) {
return new IpPrefix(Version.INET, address, netmask);
}
/**
......@@ -85,8 +85,8 @@ public final class IpAddress {
* @param address an integer representing an IP value
* @return an IP address
*/
public static IpAddress valueOf(int address) {
return new IpAddress(Version.INET, bytes(address));
public static IpPrefix valueOf(int address) {
return new IpPrefix(Version.INET, bytes(address));
}
/**
......@@ -96,8 +96,8 @@ public final class IpAddress {
* @param netmask the CIDR value subnet mask
* @return an IP address
*/
public static IpAddress valueOf(int address, int netmask) {
return new IpAddress(Version.INET, bytes(address), netmask);
public static IpPrefix valueOf(int address, int netmask) {
return new IpPrefix(Version.INET, bytes(address), netmask);
}
/**
......@@ -108,7 +108,7 @@ public final class IpAddress {
* @param address a IP address in string form, e.g. "10.0.0.1", "10.0.0.1/24"
* @return an IP address
*/
public static IpAddress valueOf(String address) {
public static IpPrefix valueOf(String address) {
final String [] parts = address.split("\\/");
if (parts.length > 2) {
......@@ -135,7 +135,7 @@ public final class IpAddress {
for (int i = 0; i < INET_LEN; i++) {
bytes[i] = (byte) Short.parseShort(net[i], 10);
}
return new IpAddress(Version.INET, bytes, mask);
return new IpPrefix(Version.INET, bytes, mask);
}
/**
......@@ -185,8 +185,8 @@ public final class IpAddress {
*
* @return the subnet mask
*/
public IpAddress netmask() {
return new IpAddress(Version.INET, bytes(mask()));
public IpPrefix netmask() {
return new IpPrefix(Version.INET, bytes(mask()));
}
/**
......@@ -196,9 +196,9 @@ public final class IpAddress {
*
* @return the network address or null
*/
public IpAddress network() {
public IpPrefix network() {
if (netmask == DEFAULT_MASK) {
return new IpAddress(version, ANY, DEFAULT_MASK);
return new IpPrefix(version, ANY, DEFAULT_MASK);
}
byte [] net = new byte [4];
......@@ -206,7 +206,7 @@ public final class IpAddress {
for (int i = 0; i < INET_LEN; i++) {
net[i] = (byte) (octets[i] & mask[i]);
}
return new IpAddress(version, net, netmask);
return new IpPrefix(version, net, netmask);
}
/**
......@@ -217,9 +217,9 @@ public final class IpAddress {
*
* @return the host address
*/
public IpAddress host() {
public IpPrefix host() {
if (netmask == DEFAULT_MASK) {
new IpAddress(version, octets, netmask);
new IpPrefix(version, octets, netmask);
}
byte [] host = new byte [INET_LEN];
......@@ -227,7 +227,7 @@ public final class IpAddress {
for (int i = 0; i < INET_LEN; i++) {
host[i] = (byte) (octets[i] & ~mask[i]);
}
return new IpAddress(version, host, netmask);
return new IpPrefix(version, host, netmask);
}
public boolean isMasked() {
......@@ -242,7 +242,7 @@ public final class IpAddress {
* @return true if the other IP address is contained in this address'
* network, otherwise false
*/
public boolean contains(IpAddress other) {
public boolean contains(IpPrefix other) {
if (this.netmask <= other.netmask) {
// Special case where they're both /32 addresses
if (this.netmask == MAX_INET_MASK) {
......@@ -250,8 +250,8 @@ public final class IpAddress {
}
// Mask the other address with our network mask
IpAddress otherMasked =
IpAddress.valueOf(other.octets, netmask).network();
IpPrefix otherMasked =
IpPrefix.valueOf(other.octets, netmask).network();
return network().equals(otherMasked);
}
......@@ -279,7 +279,7 @@ public final class IpAddress {
if (getClass() != obj.getClass()) {
return false;
}
IpAddress other = (IpAddress) obj;
IpPrefix other = (IpPrefix) obj;
if (netmask != other.netmask) {
return false;
}
......
......@@ -7,11 +7,11 @@ import static org.junit.Assert.assertTrue;
import java.util.Arrays;
import org.junit.Test;
import org.onlab.packet.IpAddress.Version;
import org.onlab.packet.IpPrefix.Version;
import com.google.common.testing.EqualsTester;
public class IPAddressTest {
public class IpPrefixTest {
private static final byte [] BYTES1 = new byte [] {0xa, 0x0, 0x0, 0xa};
private static final byte [] BYTES2 = new byte [] {0xa, 0x0, 0x0, 0xb};
......@@ -22,11 +22,11 @@ public class IPAddressTest {
@Test
public void testEquality() {
IpAddress ip1 = IpAddress.valueOf(BYTES1);
IpAddress ip2 = IpAddress.valueOf(INTVAL1);
IpAddress ip3 = IpAddress.valueOf(BYTES2);
IpAddress ip4 = IpAddress.valueOf(INTVAL2);
IpAddress ip5 = IpAddress.valueOf(STRVAL);
IpPrefix ip1 = IpPrefix.valueOf(BYTES1);
IpPrefix ip2 = IpPrefix.valueOf(INTVAL1);
IpPrefix ip3 = IpPrefix.valueOf(BYTES2);
IpPrefix ip4 = IpPrefix.valueOf(INTVAL2);
IpPrefix ip5 = IpPrefix.valueOf(STRVAL);
new EqualsTester().addEqualityGroup(ip1, ip2)
.addEqualityGroup(ip3, ip4)
......@@ -34,16 +34,16 @@ public class IPAddressTest {
.testEquals();
// string conversions
IpAddress ip6 = IpAddress.valueOf(BYTES1, MASK);
IpAddress ip7 = IpAddress.valueOf("10.0.0.10/16");
IpAddress ip8 = IpAddress.valueOf(new byte [] {0xa, 0x0, 0x0, 0xc});
IpPrefix ip6 = IpPrefix.valueOf(BYTES1, MASK);
IpPrefix ip7 = IpPrefix.valueOf("10.0.0.10/16");
IpPrefix ip8 = IpPrefix.valueOf(new byte [] {0xa, 0x0, 0x0, 0xc});
assertEquals("incorrect address conversion", ip6, ip7);
assertEquals("incorrect address conversion", ip5, ip8);
}
@Test
public void basics() {
IpAddress ip1 = IpAddress.valueOf(BYTES1, MASK);
IpPrefix ip1 = IpPrefix.valueOf(BYTES1, MASK);
final byte [] bytes = new byte [] {0xa, 0x0, 0x0, 0xa};
//check fields
......@@ -57,29 +57,29 @@ public class IPAddressTest {
@Test
public void netmasks() {
// masked
IpAddress ip1 = IpAddress.valueOf(BYTES1, MASK);
IpPrefix ip1 = IpPrefix.valueOf(BYTES1, MASK);
IpAddress host = IpAddress.valueOf("0.0.0.10/16");
IpAddress network = IpAddress.valueOf("10.0.0.0/16");
IpPrefix host = IpPrefix.valueOf("0.0.0.10/16");
IpPrefix network = IpPrefix.valueOf("10.0.0.0/16");
assertEquals("incorrect host address", host, ip1.host());
assertEquals("incorrect network address", network, ip1.network());
assertEquals("incorrect netmask", "255.255.0.0", ip1.netmask().toString());
//unmasked
IpAddress ip2 = IpAddress.valueOf(BYTES1);
IpAddress umhost = IpAddress.valueOf("10.0.0.10/0");
IpAddress umnet = IpAddress.valueOf("0.0.0.0/0");
IpPrefix ip2 = IpPrefix.valueOf(BYTES1);
IpPrefix umhost = IpPrefix.valueOf("10.0.0.10/0");
IpPrefix umnet = IpPrefix.valueOf("0.0.0.0/0");
assertEquals("incorrect host address", umhost, ip2.host());
assertEquals("incorrect host address", umnet, ip2.network());
assertTrue("incorrect netmask",
Arrays.equals(IpAddress.ANY, ip2.netmask().toOctets()));
Arrays.equals(IpPrefix.ANY, ip2.netmask().toOctets()));
}
@Test
public void testContains() {
IpAddress slash31 = IpAddress.valueOf(BYTES1, 31);
IpAddress slash32 = IpAddress.valueOf(BYTES1, 32);
IpAddress differentSlash32 = IpAddress.valueOf(BYTES2, 32);
IpPrefix slash31 = IpPrefix.valueOf(BYTES1, 31);
IpPrefix slash32 = IpPrefix.valueOf(BYTES1, 32);
IpPrefix differentSlash32 = IpPrefix.valueOf(BYTES2, 32);
assertTrue(slash31.contains(differentSlash32));
assertFalse(differentSlash32.contains(slash31));
......@@ -88,11 +88,11 @@ public class IPAddressTest {
assertFalse(slash32.contains(differentSlash32));
assertFalse(differentSlash32.contains(slash32));
IpAddress zero = IpAddress.valueOf("0.0.0.0/0");
IpPrefix zero = IpPrefix.valueOf("0.0.0.0/0");
assertTrue(zero.contains(differentSlash32));
assertFalse(differentSlash32.contains(zero));
IpAddress slash8 = IpAddress.valueOf("10.0.0.0/8");
IpPrefix slash8 = IpPrefix.valueOf("10.0.0.0/8");
assertTrue(slash8.contains(slash31));
assertFalse(slash31.contains(slash8));
}
......
......@@ -6,7 +6,7 @@ import org.junit.Test;
import com.google.common.testing.EqualsTester;
public class VLANIDTest {
public class VlanIdTest {
@Test
public void testEquality() {
......