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 { ...@@ -43,6 +43,9 @@ public class PIM extends BasePacket {
43 43
44 public static final int PIM_HEADER_LEN = 4; 44 public static final int PIM_HEADER_LEN = 4;
45 45
46 + public static final byte ADDRESS_FAMILY_IP4 = 0x1;
47 + public static final byte ADDRESS_FAMILY_IP6 = 0x2;
48 +
46 public static final Map<Byte, Deserializer<? extends IPacket>> PROTOCOL_DESERIALIZER_MAP = 49 public static final Map<Byte, Deserializer<? extends IPacket>> PROTOCOL_DESERIALIZER_MAP =
47 new HashMap<>(); 50 new HashMap<>();
48 51
......
...@@ -17,9 +17,11 @@ package org.onlab.packet.pim; ...@@ -17,9 +17,11 @@ package org.onlab.packet.pim;
17 17
18 import org.onlab.packet.DeserializationException; 18 import org.onlab.packet.DeserializationException;
19 import org.onlab.packet.Ip4Address; 19 import org.onlab.packet.Ip4Address;
20 +import org.onlab.packet.Ip6Address;
20 import org.onlab.packet.IpAddress; 21 import org.onlab.packet.IpAddress;
21 import org.onlab.packet.IpPrefix; 22 import org.onlab.packet.IpPrefix;
22 -import org.onlab.packet.Ip6Address; 23 +import org.onlab.packet.PIM;
24 +
23 25
24 import java.nio.ByteBuffer; 26 import java.nio.ByteBuffer;
25 27
...@@ -41,7 +43,7 @@ public class PIMAddrGroup { ...@@ -41,7 +43,7 @@ public class PIMAddrGroup {
41 * PIM Encoded Group Address. 43 * PIM Encoded Group Address.
42 */ 44 */
43 public PIMAddrGroup() { 45 public PIMAddrGroup() {
44 - this.family = 4; 46 + this.family = PIM.ADDRESS_FAMILY_IP4;
45 this.encType = 0; 47 this.encType = 0;
46 this.reserved = 0; 48 this.reserved = 0;
47 this.bBit = false; 49 this.bBit = false;
...@@ -83,7 +85,7 @@ public class PIMAddrGroup { ...@@ -83,7 +85,7 @@ public class PIMAddrGroup {
83 public void setAddr(IpPrefix pfx) { 85 public void setAddr(IpPrefix pfx) {
84 this.addr = pfx.address(); 86 this.addr = pfx.address();
85 this.masklen = (byte) pfx.prefixLength(); 87 this.masklen = (byte) pfx.prefixLength();
86 - this.family = (byte) ((this.addr.isIp4()) ? 4 : 6); 88 + this.family = (byte) ((this.addr.isIp4()) ? PIM.ADDRESS_FAMILY_IP4 : PIM.ADDRESS_FAMILY_IP6);
87 } 89 }
88 90
89 /** 91 /**
...@@ -181,9 +183,9 @@ public class PIMAddrGroup { ...@@ -181,9 +183,9 @@ public class PIMAddrGroup {
181 checkInput(bb.array(), bb.position(), bb.limit() - bb.position(), ENC_GROUP_IPV4_BYTE_LENGTH); 183 checkInput(bb.array(), bb.position(), bb.limit() - bb.position(), ENC_GROUP_IPV4_BYTE_LENGTH);
182 184
183 this.family = bb.get(); 185 this.family = bb.get();
184 - if (family != 4 && family != 6) { 186 + if (family != PIM.ADDRESS_FAMILY_IP4 && family != PIM.ADDRESS_FAMILY_IP6) {
185 throw new DeserializationException("Illegal IP version number: " + family + "\n"); 187 throw new DeserializationException("Illegal IP version number: " + family + "\n");
186 - } else if (family == 6) { 188 + } else if (family == PIM.ADDRESS_FAMILY_IP6) {
187 189
188 // Check for one less by since we have already read the first byte of the packet. 190 // Check for one less by since we have already read the first byte of the packet.
189 checkInput(bb.array(), bb.position(), bb.limit() - bb.position(), ENC_GROUP_IPV6_BYTE_LENGTH - 1); 191 checkInput(bb.array(), bb.position(), bb.limit() - bb.position(), ENC_GROUP_IPV6_BYTE_LENGTH - 1);
...@@ -201,9 +203,9 @@ public class PIMAddrGroup { ...@@ -201,9 +203,9 @@ public class PIMAddrGroup {
201 this.reserved |= 0x7d; 203 this.reserved |= 0x7d;
202 204
203 this.masklen = bb.get(); 205 this.masklen = bb.get();
204 - if (this.family == 4) { 206 + if (this.family == PIM.ADDRESS_FAMILY_IP4) {
205 this.addr = IpAddress.valueOf(bb.getInt()); 207 this.addr = IpAddress.valueOf(bb.getInt());
206 - } else if (this.family == 6) { 208 + } else if (this.family == PIM.ADDRESS_FAMILY_IP6) {
207 this.addr = Ip6Address.valueOf(bb.array(), 2); 209 this.addr = Ip6Address.valueOf(bb.array(), 2);
208 } 210 }
209 return this; 211 return this;
......
...@@ -17,9 +17,10 @@ package org.onlab.packet.pim; ...@@ -17,9 +17,10 @@ package org.onlab.packet.pim;
17 17
18 import org.onlab.packet.DeserializationException; 18 import org.onlab.packet.DeserializationException;
19 import org.onlab.packet.Ip4Address; 19 import org.onlab.packet.Ip4Address;
20 +import org.onlab.packet.Ip6Address;
20 import org.onlab.packet.IpAddress; 21 import org.onlab.packet.IpAddress;
21 import org.onlab.packet.IpPrefix; 22 import org.onlab.packet.IpPrefix;
22 -import org.onlab.packet.Ip6Address; 23 +import org.onlab.packet.PIM;
23 24
24 import java.nio.ByteBuffer; 25 import java.nio.ByteBuffer;
25 26
...@@ -66,7 +67,7 @@ public class PIMAddrSource { ...@@ -66,7 +67,7 @@ public class PIMAddrSource {
66 } 67 }
67 68
68 private void init() { 69 private void init() {
69 - this.family = 4; 70 + this.family = PIM.ADDRESS_FAMILY_IP4;
70 this.encType = 0; 71 this.encType = 0;
71 this.reserved = 0; 72 this.reserved = 0;
72 this.sBit = true; 73 this.sBit = true;
...@@ -92,7 +93,7 @@ public class PIMAddrSource { ...@@ -92,7 +93,7 @@ public class PIMAddrSource {
92 public void setAddr(IpPrefix spfx) { 93 public void setAddr(IpPrefix spfx) {
93 this.addr = spfx.address(); 94 this.addr = spfx.address();
94 this.masklen = (byte) spfx.prefixLength(); 95 this.masklen = (byte) spfx.prefixLength();
95 - this.family = (byte) ((this.addr.isIp4()) ? 4 : 6); 96 + this.family = (byte) ((this.addr.isIp4()) ? PIM.ADDRESS_FAMILY_IP4 : PIM.ADDRESS_FAMILY_IP6);
96 } 97 }
97 98
98 /** 99 /**
...@@ -156,7 +157,7 @@ public class PIMAddrSource { ...@@ -156,7 +157,7 @@ public class PIMAddrSource {
156 */ 157 */
157 public int getByteSize() { 158 public int getByteSize() {
158 int size = 4; 159 int size = 4;
159 - size += addr.isIp4() ? 4 : 16; 160 + size += addr.isIp4() ? PIM.ADDRESS_FAMILY_IP4 : PIM.ADDRESS_FAMILY_IP6;
160 return size; 161 return size;
161 } 162 }
162 163
...@@ -202,9 +203,9 @@ public class PIMAddrSource { ...@@ -202,9 +203,9 @@ public class PIMAddrSource {
202 checkInput(bb.array(), bb.position(), bb.limit() - bb.position(), ENC_SOURCE_IPV4_BYTE_LENGTH); 203 checkInput(bb.array(), bb.position(), bb.limit() - bb.position(), ENC_SOURCE_IPV4_BYTE_LENGTH);
203 204
204 this.family = bb.get(); 205 this.family = bb.get();
205 - if (family != 4 && family != 6) { 206 + if (family != PIM.ADDRESS_FAMILY_IP4 && family != PIM.ADDRESS_FAMILY_IP6) {
206 throw new DeserializationException("Illegal IP version number: " + family + "\n"); 207 throw new DeserializationException("Illegal IP version number: " + family + "\n");
207 - } else if (family == 6) { 208 + } else if (family == PIM.ADDRESS_FAMILY_IP6) {
208 209
209 // Check for one less by since we have already read the first byte of the packet. 210 // Check for one less by since we have already read the first byte of the packet.
210 checkInput(bb.array(), bb.position(), bb.limit() - bb.position(), ENC_SOURCE_IPV6_BYTE_LENGTH - 1); 211 checkInput(bb.array(), bb.position(), bb.limit() - bb.position(), ENC_SOURCE_IPV6_BYTE_LENGTH - 1);
...@@ -226,9 +227,9 @@ public class PIMAddrSource { ...@@ -226,9 +227,9 @@ public class PIMAddrSource {
226 this.reserved &= 0xf8; 227 this.reserved &= 0xf8;
227 228
228 this.masklen = bb.get(); 229 this.masklen = bb.get();
229 - if (this.family == 4) { 230 + if (this.family == PIM.ADDRESS_FAMILY_IP4) {
230 this.addr = IpAddress.valueOf(bb.getInt()); 231 this.addr = IpAddress.valueOf(bb.getInt());
231 - } else if (this.family == 6) { 232 + } else if (this.family == PIM.ADDRESS_FAMILY_IP6) {
232 this.addr = Ip6Address.valueOf(bb.array(), 2); 233 this.addr = Ip6Address.valueOf(bb.array(), 2);
233 } 234 }
234 return this; 235 return this;
......
...@@ -15,10 +15,13 @@ ...@@ -15,10 +15,13 @@
15 */ 15 */
16 package org.onlab.packet.pim; 16 package org.onlab.packet.pim;
17 17
18 +
19 +
18 import org.onlab.packet.DeserializationException; 20 import org.onlab.packet.DeserializationException;
19 import org.onlab.packet.Ip4Address; 21 import org.onlab.packet.Ip4Address;
20 -import org.onlab.packet.IpAddress;
21 import org.onlab.packet.Ip6Address; 22 import org.onlab.packet.Ip6Address;
23 +import org.onlab.packet.IpAddress;
24 +import org.onlab.packet.PIM;
22 25
23 import java.nio.ByteBuffer; 26 import java.nio.ByteBuffer;
24 27
...@@ -36,7 +39,7 @@ public class PIMAddrUnicast { ...@@ -36,7 +39,7 @@ public class PIMAddrUnicast {
36 * PIM Encoded Source Address. 39 * PIM Encoded Source Address.
37 */ 40 */
38 public PIMAddrUnicast() { 41 public PIMAddrUnicast() {
39 - this.family = 4; 42 + this.family = PIM.ADDRESS_FAMILY_IP4;
40 this.encType = 0; 43 this.encType = 0;
41 } 44 }
42 45
...@@ -48,9 +51,9 @@ public class PIMAddrUnicast { ...@@ -48,9 +51,9 @@ public class PIMAddrUnicast {
48 public PIMAddrUnicast(String addr) { 51 public PIMAddrUnicast(String addr) {
49 this.addr = IpAddress.valueOf(addr); 52 this.addr = IpAddress.valueOf(addr);
50 if (this.addr.isIp4()) { 53 if (this.addr.isIp4()) {
51 - this.family = 4; 54 + this.family = PIM.ADDRESS_FAMILY_IP4;
52 } else { 55 } else {
53 - this.family = 6; 56 + this.family = PIM.ADDRESS_FAMILY_IP6;
54 } 57 }
55 this.encType = 0; 58 this.encType = 0;
56 } 59 }
...@@ -63,9 +66,9 @@ public class PIMAddrUnicast { ...@@ -63,9 +66,9 @@ public class PIMAddrUnicast {
63 public void setAddr(IpAddress addr) { 66 public void setAddr(IpAddress addr) {
64 this.addr = addr; 67 this.addr = addr;
65 if (this.addr.isIp4()) { 68 if (this.addr.isIp4()) {
66 - this.family = 4; 69 + this.family = PIM.ADDRESS_FAMILY_IP4;
67 } else { 70 } else {
68 - this.family = 6; 71 + this.family = PIM.ADDRESS_FAMILY_IP6;
69 } 72 }
70 } 73 }
71 74
...@@ -121,17 +124,17 @@ public class PIMAddrUnicast { ...@@ -121,17 +124,17 @@ public class PIMAddrUnicast {
121 this.family = bb.get(); 124 this.family = bb.get();
122 125
123 // If we have IPv6 we need to ensure we have adequate buffer space. 126 // If we have IPv6 we need to ensure we have adequate buffer space.
124 - if (this.family != 4 && this.family != 6) { 127 + if (this.family != PIM.ADDRESS_FAMILY_IP4 && this.family != PIM.ADDRESS_FAMILY_IP6) {
125 throw new DeserializationException("Invalid address family: " + this.family); 128 throw new DeserializationException("Invalid address family: " + this.family);
126 - } else if (this.family == 6) { 129 + } else if (this.family == PIM.ADDRESS_FAMILY_IP6) {
127 // Subtract -1 from ENC_UNICAST_IPv6 BYTE_LENGTH because we read one byte for family previously. 130 // Subtract -1 from ENC_UNICAST_IPv6 BYTE_LENGTH because we read one byte for family previously.
128 checkInput(bb.array(), bb.position(), bb.limit() - bb.position(), ENC_UNICAST_IPV6_BYTE_LENGTH - 1); 131 checkInput(bb.array(), bb.position(), bb.limit() - bb.position(), ENC_UNICAST_IPV6_BYTE_LENGTH - 1);
129 } 132 }
130 133
131 this.encType = bb.get(); 134 this.encType = bb.get();
132 - if (this.family == 4) { 135 + if (this.family == PIM.ADDRESS_FAMILY_IP4) {
133 this.addr = IpAddress.valueOf(bb.getInt()); 136 this.addr = IpAddress.valueOf(bb.getInt());
134 - } else if (this.family == 6) { 137 + } else if (this.family == PIM.ADDRESS_FAMILY_IP6) {
135 this.addr = Ip6Address.valueOf(bb.array(), 2); 138 this.addr = Ip6Address.valueOf(bb.array(), 2);
136 } 139 }
137 return this; 140 return this;
......