Rusty Eddy
Committed by Gerrit Code Review

Added symbolic names with the correct values for

PIM Address families IPv4 and IPv6

Change-Id: I8ae675fa1df052c4ef0b73b27449add534cc5c3c
......@@ -43,6 +43,9 @@ public class PIM extends BasePacket {
public static final int PIM_HEADER_LEN = 4;
public static final byte ADDRESS_FAMILY_IP4 = 0x1;
public static final byte ADDRESS_FAMILY_IP6 = 0x2;
public static final Map<Byte, Deserializer<? extends IPacket>> PROTOCOL_DESERIALIZER_MAP =
new HashMap<>();
......
......@@ -17,9 +17,11 @@ package org.onlab.packet.pim;
import org.onlab.packet.DeserializationException;
import org.onlab.packet.Ip4Address;
import org.onlab.packet.Ip6Address;
import org.onlab.packet.IpAddress;
import org.onlab.packet.IpPrefix;
import org.onlab.packet.Ip6Address;
import org.onlab.packet.PIM;
import java.nio.ByteBuffer;
......@@ -41,7 +43,7 @@ public class PIMAddrGroup {
* PIM Encoded Group Address.
*/
public PIMAddrGroup() {
this.family = 4;
this.family = PIM.ADDRESS_FAMILY_IP4;
this.encType = 0;
this.reserved = 0;
this.bBit = false;
......@@ -83,7 +85,7 @@ public class PIMAddrGroup {
public void setAddr(IpPrefix pfx) {
this.addr = pfx.address();
this.masklen = (byte) pfx.prefixLength();
this.family = (byte) ((this.addr.isIp4()) ? 4 : 6);
this.family = (byte) ((this.addr.isIp4()) ? PIM.ADDRESS_FAMILY_IP4 : PIM.ADDRESS_FAMILY_IP6);
}
/**
......@@ -181,9 +183,9 @@ public class PIMAddrGroup {
checkInput(bb.array(), bb.position(), bb.limit() - bb.position(), ENC_GROUP_IPV4_BYTE_LENGTH);
this.family = bb.get();
if (family != 4 && family != 6) {
if (family != PIM.ADDRESS_FAMILY_IP4 && family != PIM.ADDRESS_FAMILY_IP6) {
throw new DeserializationException("Illegal IP version number: " + family + "\n");
} else if (family == 6) {
} else if (family == PIM.ADDRESS_FAMILY_IP6) {
// Check for one less by since we have already read the first byte of the packet.
checkInput(bb.array(), bb.position(), bb.limit() - bb.position(), ENC_GROUP_IPV6_BYTE_LENGTH - 1);
......@@ -201,9 +203,9 @@ public class PIMAddrGroup {
this.reserved |= 0x7d;
this.masklen = bb.get();
if (this.family == 4) {
if (this.family == PIM.ADDRESS_FAMILY_IP4) {
this.addr = IpAddress.valueOf(bb.getInt());
} else if (this.family == 6) {
} else if (this.family == PIM.ADDRESS_FAMILY_IP6) {
this.addr = Ip6Address.valueOf(bb.array(), 2);
}
return this;
......
......@@ -17,9 +17,10 @@ package org.onlab.packet.pim;
import org.onlab.packet.DeserializationException;
import org.onlab.packet.Ip4Address;
import org.onlab.packet.Ip6Address;
import org.onlab.packet.IpAddress;
import org.onlab.packet.IpPrefix;
import org.onlab.packet.Ip6Address;
import org.onlab.packet.PIM;
import java.nio.ByteBuffer;
......@@ -66,7 +67,7 @@ public class PIMAddrSource {
}
private void init() {
this.family = 4;
this.family = PIM.ADDRESS_FAMILY_IP4;
this.encType = 0;
this.reserved = 0;
this.sBit = true;
......@@ -92,7 +93,7 @@ public class PIMAddrSource {
public void setAddr(IpPrefix spfx) {
this.addr = spfx.address();
this.masklen = (byte) spfx.prefixLength();
this.family = (byte) ((this.addr.isIp4()) ? 4 : 6);
this.family = (byte) ((this.addr.isIp4()) ? PIM.ADDRESS_FAMILY_IP4 : PIM.ADDRESS_FAMILY_IP6);
}
/**
......@@ -156,7 +157,7 @@ public class PIMAddrSource {
*/
public int getByteSize() {
int size = 4;
size += addr.isIp4() ? 4 : 16;
size += addr.isIp4() ? PIM.ADDRESS_FAMILY_IP4 : PIM.ADDRESS_FAMILY_IP6;
return size;
}
......@@ -202,9 +203,9 @@ public class PIMAddrSource {
checkInput(bb.array(), bb.position(), bb.limit() - bb.position(), ENC_SOURCE_IPV4_BYTE_LENGTH);
this.family = bb.get();
if (family != 4 && family != 6) {
if (family != PIM.ADDRESS_FAMILY_IP4 && family != PIM.ADDRESS_FAMILY_IP6) {
throw new DeserializationException("Illegal IP version number: " + family + "\n");
} else if (family == 6) {
} else if (family == PIM.ADDRESS_FAMILY_IP6) {
// Check for one less by since we have already read the first byte of the packet.
checkInput(bb.array(), bb.position(), bb.limit() - bb.position(), ENC_SOURCE_IPV6_BYTE_LENGTH - 1);
......@@ -226,9 +227,9 @@ public class PIMAddrSource {
this.reserved &= 0xf8;
this.masklen = bb.get();
if (this.family == 4) {
if (this.family == PIM.ADDRESS_FAMILY_IP4) {
this.addr = IpAddress.valueOf(bb.getInt());
} else if (this.family == 6) {
} else if (this.family == PIM.ADDRESS_FAMILY_IP6) {
this.addr = Ip6Address.valueOf(bb.array(), 2);
}
return this;
......
......@@ -15,10 +15,13 @@
*/
package org.onlab.packet.pim;
import org.onlab.packet.DeserializationException;
import org.onlab.packet.Ip4Address;
import org.onlab.packet.IpAddress;
import org.onlab.packet.Ip6Address;
import org.onlab.packet.IpAddress;
import org.onlab.packet.PIM;
import java.nio.ByteBuffer;
......@@ -36,7 +39,7 @@ public class PIMAddrUnicast {
* PIM Encoded Source Address.
*/
public PIMAddrUnicast() {
this.family = 4;
this.family = PIM.ADDRESS_FAMILY_IP4;
this.encType = 0;
}
......@@ -48,9 +51,9 @@ public class PIMAddrUnicast {
public PIMAddrUnicast(String addr) {
this.addr = IpAddress.valueOf(addr);
if (this.addr.isIp4()) {
this.family = 4;
this.family = PIM.ADDRESS_FAMILY_IP4;
} else {
this.family = 6;
this.family = PIM.ADDRESS_FAMILY_IP6;
}
this.encType = 0;
}
......@@ -63,9 +66,9 @@ public class PIMAddrUnicast {
public void setAddr(IpAddress addr) {
this.addr = addr;
if (this.addr.isIp4()) {
this.family = 4;
this.family = PIM.ADDRESS_FAMILY_IP4;
} else {
this.family = 6;
this.family = PIM.ADDRESS_FAMILY_IP6;
}
}
......@@ -121,17 +124,17 @@ public class PIMAddrUnicast {
this.family = bb.get();
// If we have IPv6 we need to ensure we have adequate buffer space.
if (this.family != 4 && this.family != 6) {
if (this.family != PIM.ADDRESS_FAMILY_IP4 && this.family != PIM.ADDRESS_FAMILY_IP6) {
throw new DeserializationException("Invalid address family: " + this.family);
} else if (this.family == 6) {
} else if (this.family == PIM.ADDRESS_FAMILY_IP6) {
// Subtract -1 from ENC_UNICAST_IPv6 BYTE_LENGTH because we read one byte for family previously.
checkInput(bb.array(), bb.position(), bb.limit() - bb.position(), ENC_UNICAST_IPV6_BYTE_LENGTH - 1);
}
this.encType = bb.get();
if (this.family == 4) {
if (this.family == PIM.ADDRESS_FAMILY_IP4) {
this.addr = IpAddress.valueOf(bb.getInt());
} else if (this.family == 6) {
} else if (this.family == PIM.ADDRESS_FAMILY_IP6) {
this.addr = Ip6Address.valueOf(bb.array(), 2);
}
return this;
......