private static NodeConnectorId inPortMatch(Match sourceMatch) { MatchField inPort = sourceMatch.getField(MatchType.IN_PORT); if(inPort != null && inPort.getValue() != null && (inPort.getValue() instanceof NodeConnector)) { NodeConnector port = (NodeConnector)inPort.getValue(); return (NodeConnectorId)MDFlowMapping.toUri(port); } return null; }
/** * 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(); } }
/** * Full match constructor * * @param type * @param value */ public MatchField(MatchType type, Object value) { this.type = type; this.value = value; this.mask = null; // Keep this logic, value checked only if type check is fine this.isValid = checkValueType() && checkValues(); }
intersection.setField(other.getField(type).clone()); continue; } else if (other.isAny(type)) { intersection.setField(this.getField(type).clone()); continue; MatchField thisField = this.getField(type); MatchField otherField = other.getField(type); InetAddress thisAddress = (InetAddress) thisField.getValue(); InetAddress otherAddress = (InetAddress) otherField.getValue(); InetAddress thisMask = (InetAddress) thisField.getMask(); InetAddress otherMask = (InetAddress) otherField.getMask(); .getSubnetMaskLength(otherMask); if (thisMaskLen < otherMaskLen) { intersection.setField(new MatchField(type, NetUtils.getSubnetPrefix(otherAddress, otherMaskLen), otherMask)); } else { intersection.setField(new MatchField(type, NetUtils.getSubnetPrefix(thisAddress, thisMaskLen), thisMask)); intersection.setField(this.getField(type).clone());
case DL_SRC: case DL_DST: if (!Arrays.equals((byte[]) thisField.getValue(), (byte[]) otherField.getValue())) { return false; case NW_SRC: case NW_DST: InetAddress thisAddress = (InetAddress) thisField.getValue(); InetAddress otherAddress = (InetAddress) otherField.getValue(); return false; InetAddress thisMask = (InetAddress) thisField.getMask(); InetAddress otherMask = (InetAddress) otherField.getMask(); if (NetUtils.inetAddressConflict(thisAddress, otherAddress, thisMask, otherMask) && NetUtils.inetAddressConflict(otherAddress, thisAddress, otherMask, thisMask)) { if (!thisField.getValue().equals(otherField.getValue())) { return false;
match.setField(new MatchField(MatchType.IN_PORT, incoming_connector)); match.setField(new MatchField(MatchType.DL_DST, dstMAC.clone())); installFlow(match, actions, incoming_node, (short) 1);
/** * Returns a reversed version of this match * For example, in the reversed version the network source and destination * addresses will be exchanged. Non symmetric match field will not be * copied over into the reversed match version, like input port. * * @return */ public Match reverse() { // Copy over all fields Match reverse = this.clone(); // Flip symmetric fields for (Map.Entry<MatchType, MatchType> entry : Match.reversableMatches.entrySet()) { MatchType from = entry.getKey(); MatchType to = entry.getValue(); if (this.isPresent(from)) { reverse.setField(to, this.getField(from).getValue(), this.getField(from).getMask()); if (!this.isPresent(to)) { reverse.clearField(from); } } } // Reset asymmetric fields reverse.clearField(MatchType.IN_PORT); return reverse; }
salMatch.setField(new MatchField(MatchType.IN_PORT, NodeConnectorCreator.createNodeConnector( ofMatch.getInputPort(), node))); .isZeroMAC(ofMatch.getDataLayerSource())) { byte srcMac[] = ofMatch.getDataLayerSource(); salMatch.setField(new MatchField(MatchType.DL_SRC, srcMac.clone())); .getDataLayerDestination())) { byte dstMac[] = ofMatch.getDataLayerDestination(); salMatch.setField(new MatchField(MatchType.DL_DST, dstMac.clone())); salMatch.setField(new MatchField(MatchType.DL_TYPE, ofMatch.getDataLayerType())); salMatch.setField(new MatchField(MatchType.DL_VLAN, vlan)); salMatch.setField(new MatchField(MatchType.IN_PORT, NodeConnectorCreator.createOFNodeConnector( v6Match.getInputPort(), node))); .isZeroMAC(ofMatch.getDataLayerSource())) { byte srcMac[] = v6Match.getDataLayerSource(); salMatch.setField(new MatchField(MatchType.DL_SRC, srcMac.clone()));
private static Integer transportPort(final Match sourceMatch, final MatchType matchType) { MatchField transportPort = sourceMatch.getField(matchType); if (transportPort != null && transportPort.getValue() != null && transportPort.getValue().getClass().equals(Short.class)) { return NetUtils.getUnsignedShort((short) transportPort.getValue()); } return null; }
if (match.isPresent(MatchType.IN_PORT)) { short port = (Short) ((NodeConnector) match.getField( MatchType.IN_PORT).getValue()).getID(); if (!isIPv6) { ofMatch.setInputPort(port); .getValue(); if (!isIPv6) { ofMatch.setDataLayerSource(srcMac.clone()); .getValue(); if (!isIPv6) { ofMatch.setDataLayerDestination(dstMac.clone()); .getValue(); if (vlan == MatchType.DL_VLAN_NONE) { vlan = OFP_VLAN_NONE; .getValue(); if (!isIPv6) { ofMatch.setDataLayerVirtualLanPriorityCodePoint(vlanPr); .getValue(); if (!isIPv6) { ofMatch.setDataLayerType(ethType); byte tos = (Byte) match.getField(MatchType.NW_TOS).getValue(); byte dscp = (byte) (tos << 2); if (!isIPv6) {
/** * 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(); } }
/** * Mask based match constructor * * @param type * @param value * @param mask * has to be of the same class type of value. A null mask means * full match */ public MatchField(MatchType type, Object value, Object mask) { this.type = type; this.value = value; this.mask = mask; // Keep this logic, value checked only if type check is fine this.isValid = checkValueType() && checkValues(); }
private static IpMatch ipMatch(final Match sourceMatch) { IpMatchBuilder targetIpMatchBuild = new IpMatchBuilder(); MatchField networkTos = sourceMatch.getField(MatchType.NW_TOS); if (networkTos != null && networkTos.getValue() != null) { Dscp dscp = new Dscp( (short) (NetUtils.getUnsignedByte((Byte) networkTos .getValue()))); targetIpMatchBuild.setIpDscp(dscp); } MatchField protocol = sourceMatch.getField(MatchType.NW_PROTO); if (protocol != null && protocol.getValue() != null) { targetIpMatchBuild.setIpProtocol((short) ((byte) protocol .getValue())); } if((networkTos != null && networkTos.getValue() != null) || (protocol != null && protocol.getValue() != null)) { return targetIpMatchBuild.build(); } return null; }
private static Layer3Match layer3Match(final Match sourceMatch) { InetAddress inetSourceAddress = null; MatchField netSource = sourceMatch.getField(MatchType.NW_SRC); if (netSource != null && netSource.getValue() != null) { inetSourceAddress = (InetAddress) (netSource.getValue()); if (netDest != null && netDest.getValue() != null) { inetDestAddress = (InetAddress) (netDest.getValue()); MatchField dataLinkType = sourceMatch.getField(DL_TYPE); Short dLType = null; if (dataLinkType != null && dataLinkType.getValue() != null) { dLType = (Short) (dataLinkType.getValue());
private static Layer4Match layer4Match(final Match sourceMatch) { MatchField nwProto = sourceMatch.getField(MatchType.NW_PROTO); Short nwProtocolSource = null; if (nwProto != null && nwProto.getValue() != null) { nwProtocolSource = (short) ((byte) nwProto.getValue()); switch (nwProtocolSource) { case TCP: return Layer4MatchAsTcp(sourceMatch); case UDP: return Layer4MatchAsUdp(sourceMatch); case CRUDP: return Layer4MatchAsSctp(sourceMatch); } } return null; }
private static VlanMatch vlanMatch(final Match sourceMatch) { VlanMatchBuilder vlanMatchBuild = new VlanMatchBuilder(); MatchField vlan = sourceMatch.getField(MatchType.DL_VLAN); if (vlan != null && vlan.getValue() != null) { VlanIdBuilder vlanIDBuilder = new VlanIdBuilder(); short vid = (short)vlan.getValue(); boolean present = (vid != MatchType.DL_VLAN_NONE); vlanIDBuilder.setVlanId(new VlanId((NetUtils .getUnsignedShort(vid)))); vlanIDBuilder.setVlanIdPresent(present); vlanMatchBuild.setVlanId(vlanIDBuilder.build()); } MatchField vlanPriority = sourceMatch.getField(MatchType.DL_VLAN_PR); if (vlanPriority != null && vlanPriority.getValue() != null) { vlanMatchBuild.setVlanPcp(new VlanPcp((short) ((byte) vlanPriority .getValue()))); } if((vlan != null && vlan.getValue() != null) || (vlanPriority != null && vlanPriority.getValue() != null)) { return vlanMatchBuild.build(); } return null; }
/** * Returns whether this match is for an IPv6 flow */ public boolean isIPv6() { return (isPresent(MatchType.DL_TYPE) && ((Short) getField(MatchType.DL_TYPE).getValue()) .equals(EtherTypes.IPv6.shortValue()) || isPresent(MatchType.NW_PROTO) && ((Byte) getField(MatchType.NW_PROTO).getValue()) .equals(IPProtocols.IPV6ICMP.byteValue()) || isPresent(MatchType.NW_SRC) && getField(MatchType.NW_SRC).getValue() instanceof Inet6Address || isPresent(MatchType.NW_DST) && getField(MatchType.NW_DST).getValue() instanceof Inet6Address); }
InetAddress srcIp = (InetAddress) f.getMatch().getField(MatchType.NW_SRC).getValue(); InetAddress dstIp = (InetAddress) f.getMatch().getField(MatchType.NW_DST).getValue(); flowName = "[" + groupName + ":" + srcIp + ":" + dstIp + "]"; List<Action> actions = calcForwardingActions(node, srcIp, dstIp, attribs.get(groupName));