private boolean checkValueType() { if (type.isCongruentType(value, mask) == false) { String valueClass = (value == null) ? "null" : value.getClass().getSimpleName(); String maskClass = (mask == null) ? "null" : mask.getClass().getSimpleName(); String error = "Invalid match field's value or mask types.For field: " + type.id() + " Expected:" + type.dataType().getSimpleName() + " or equivalent," + " Got:(" + valueClass + "," + maskClass + ")"; throwException(error); return false; } return true; }
@XmlElement(name = "value") private String getValueString() { return type.stringify(value); }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } MatchField other = (MatchField) obj; if (type != other.type) { return false; } return type.equals(this.value, other.value, this.mask, other.mask); } }
private boolean checkValues() { if (type.isValid(value, mask) == false) { String maskString = (mask == null) ? "null" : ("0x" + Integer .toHexString(Integer.parseInt(mask.toString()))); String error = "Invalid match field's value or mask assignement.For field: " + type.id() + " Expected: " + type.getRange() + ", Got:(0x" + Integer.toHexString(Integer.parseInt(value.toString())) + "," + maskString + ")"; throwException(error); return false; } return true; }
public boolean equals(Object value1, Object value2, Object mask1, Object mask2) { switch (this) { case NW_SRC: case NW_DST: // Equality to be checked against prefix addresses InetAddress thisIP = (InetAddress) value1; int thisMaskLen = (mask1 == null) ? ((thisIP instanceof Inet4Address) ? 32 : 128) : NetUtils .getSubnetMaskLength((InetAddress) mask1); InetAddress otherIP = (InetAddress) value2; int otherMaskLen = (mask2 == null) ? ((otherIP instanceof Inet4Address) ? 32 : 128) : NetUtils .getSubnetMaskLength((InetAddress) mask2); return NetUtils.getSubnetPrefix(thisIP, thisMaskLen) .equals(NetUtils.getSubnetPrefix(otherIP, otherMaskLen)); default: return (this.equalValues(value1, value2) && this.equalMasks(mask1, mask2)); } }
row.put("nodeName", desc); if (match.isPresent(MatchType.IN_PORT)) { row.put(MatchType.IN_PORT.id(), ((NodeConnector) flow.getMatch() .getField(MatchType.IN_PORT).getValue()) .getNodeConnectorIdAsString()); } else { row.put(MatchType.IN_PORT.id(), "*"); row.put(MatchType.DL_SRC.id(), (HexEncode.bytesToHexString(((byte[]) flow.getMatch() .getField(MatchType.DL_SRC).getValue())))); } else { row.put(MatchType.DL_SRC.id(), "*"); row.put(MatchType.DL_DST.id(), (HexEncode.bytesToHexString(((byte[]) flow.getMatch() .getField(MatchType.DL_DST).getValue())))); } else { row.put(MatchType.DL_DST.id(), "*"); row.put(MatchType.DL_TYPE.id(), EtherTypes.getEtherTypeName(((Short) flow.getMatch() .getField(MatchType.DL_TYPE).getValue()))); } else { row.put(MatchType.DL_TYPE.id(), "*"); if (((Short) flow.getMatch().getField(MatchType.DL_VLAN).getValue()) .shortValue() < 0) { row.put(MatchType.DL_VLAN.id(), "0");
/** * Generic method to clear a field from the match */ public void clearField(MatchType type) { fields.remove(type); matches &= ~type.getIndex(); }
@Override public int hashCode() { final int prime = 31; int result = 1; if (this.fields == null) { result = prime * result; } else { // use a tree map as the order of hashMap is not guaranteed. // 2 Match objects with fields in different order are still equal. // Hence the hashCode should be the same too. TreeMap<MatchType, MatchField> tm = new TreeMap<MatchType, MatchField>(this.fields); for (MatchType field : tm.keySet()) { MatchField f = tm.get(field); int fieldHashCode = (field==null ? 0 : field.calculateConsistentHashCode()) ^ (f==null ? 0 : f.hashCode()); result = prime * result + fieldHashCode; } } result = prime * result + matches; return result; }
/** * Returns the bitmask set for this field match * * @return */ public long getBitMask() { return type.getBitMask(mask); }
/** * Generic setter for frame/packet/message's header fields against which to match * Note: For MAC addresses, please pass the cloned value to this function * * @param type packet's header field type * @param value field's value to assign to the match */ public void setField(MatchType type, Object value) { MatchField field = new MatchField(type, value); if (field.isValid()) { fields.put(type, field); matches |= type.getIndex(); } }
Class<?> e = this.dataType(); Class<?> g = value.getClass();
public int hashCode(Object v, Object m) { final int prime = 31; int result = 1; result = prime * result + this.calculateConsistentHashCode(); switch (this) { case DL_SRC: case DL_DST: result = prime * result + ((v == null)? 0 : NetUtils.byteArray4ToInt((byte[])v)); result = prime * result + ((m == null)? 0 : NetUtils.byteArray4ToInt((byte[])m)); break; case NW_SRC: case NW_DST: // Hash code has to take into account only prefix address InetAddress ip = (InetAddress) v; int maskLen = (m == null) ? ((ip instanceof Inet4Address) ? 32 : 128) : NetUtils .getSubnetMaskLength((InetAddress) m); InetAddress prefix = NetUtils.getSubnetPrefix(ip, maskLen); result = prime * result + ((v == null)? 0 : prefix.hashCode()); break; default: result = prime * result + ((v == null)? 0 : v.hashCode()); result = prime * result + ((m == null)? 0 : m.hashCode()); } return result; } public boolean equalValues(Object a, Object b) {
@XmlElement(name = "mask") private String getMaskString() { return type.stringify(mask); }
/** * Generic setter for frame/packet/message's header fields against which to match * Note: For MAC addresses, please pass the cloned value to this function * * @param type packet's header field type * @param value field's value to assign to the match * @param mask field's bitmask to apply to the match (has to be of the same class type of value) */ public void setField(MatchType type, Object value, Object mask) { MatchField field = new MatchField(type, value, mask); if (field.isValid()) { fields.put(type, field); matches |= type.getIndex(); } }
if (this.dataType() == Byte[].class) { if (mask == null) { return 0xffffffffffffL;
String dstMac = MatchType.DL_DST.stringify(dst.getValue()); String hostMac = ((EthernetAddress) h.getDataLayerAddress()).getMacAddress(); if (dstMac.equals(hostMac)) {
/** * Generic setter for frame/packet/message's header field against which to match * * @param field the fields parameters as MAtchField object */ public void setField(MatchField field) { if (field.isValid()) { fields.put(field.getType(), field); matches |= field.getType().getIndex(); } }