- public String stringify(Object value) {
- if (value == null) {
- return null;
- }
-
- switch (this) {
- case DL_DST:
- case DL_SRC:
- return HexEncode.bytesToHexStringFormat((byte[])value);
- case DL_TYPE:
- case DL_VLAN:
- if ((Short)value < 0) {
- return ((Integer) (((Short)value).intValue() & 0x7FFF | 0x8000)).toString();
- }
- break;
- case NW_SRC:
- case NW_DST:
- return ((InetAddress)value).getHostAddress();
- case TP_SRC:
- case TP_DST:
- if ((Short)value < 0) {
- return ((Integer) (((Short)value).intValue() & 0x7FFF | 0x8000)).toString();
- }
- break;
- default:
- break;
- }
- return value.toString();
- }
+ public String stringify(Object value) {
+ if (value == null) {
+ return null;
+ }
+
+ switch (this) {
+ case DL_DST:
+ case DL_SRC:
+ return HexEncode.bytesToHexStringFormat((byte[]) value);
+ case DL_TYPE:
+ case DL_VLAN:
+ return ((Integer) NetUtils.getUnsignedShort((Short) value))
+ .toString();
+ case NW_SRC:
+ case NW_DST:
+ return ((InetAddress) value).getHostAddress();
+ case NW_TOS:
+ return ((Integer) NetUtils.getUnsignedByte((Byte) value))
+ .toString();
+ case TP_SRC:
+ case TP_DST:
+ return ((Integer) NetUtils.getUnsignedShort((Short) value))
+ .toString();
+ default:
+ break;
+ }
+ return value.toString();
+ }
+
+ public boolean equalValues(Object a, Object b) {
+ if (a == b) {
+ return true;
+ }
+ if (a == null || b == null) {
+ return false;
+ }
+ switch (this) {
+ case DL_DST:
+ case DL_SRC:
+ return Arrays.equals((byte[]) a, (byte[]) b);
+ default:
+ return a.equals(b);
+ }
+ }
+
+ public boolean equalMasks(Object a, Object b) {
+ if (a == b) {
+ return true;
+ }
+ switch (this) {
+ case NW_SRC:
+ case NW_DST:
+ /*
+ * For network address mask, network node may return full mask for
+ * flows the controller generated with a null mask object
+ */
+ byte maskBytes[] = null;
+ if (a == null) {
+ maskBytes = ((InetAddress) b).getAddress();
+ } else if (b == null) {
+ maskBytes = ((InetAddress) a).getAddress();
+ }
+ if (maskBytes != null) {
+ return (NetUtils.getSubnetMaskLength(maskBytes) == 0);
+ }
+ default:
+ if (a == null) {
+ return false;
+ }
+ return a.equals(b);
+ }
+ }