private List<FlowOnNode> forwardingTableEntriesToFlows(Map<String, Integer> entries, Node node){ List<FlowOnNode> list = new ArrayList<FlowOnNode>(); for(Map.Entry<String, Integer> entry : entries.entrySet()){ Match match = new Match(); String str = entry.getKey(); short vlan = Short.parseShort(str.substring(0, str.indexOf("."))); byte[] macAddrBytes = OIDToMacAddrBytes(str.substring(str.indexOf(".") + 1)); if(macAddrBytes == null){ logger.debug("ERROR: forwardingTableEntriesToFlows(): nodeID is {}, call OIDToMacAddrBytes() fail", (Long)node.getID()); return null; } match.setField(MatchType.DL_VLAN, vlan); match.setField(MatchType.DL_DST, macAddrBytes); List<Action> actions = new ArrayList<Action>(); NodeConnector oport = NodeConnectorCreator.createNodeConnector("SNMP", Short.parseShort(entry.getValue().toString()), node); actions.add(new Output(oport)); Flow flow = new Flow(match, actions); list.add(new FlowOnNode(flow)); } return list; }
/** * 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); }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } ContainerFlow other = (ContainerFlow) obj; if (match == null) { if (other.match != null) { return false; } } else if (!match.equals(other.match)) { return false; } return true; }
/** * 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; }
private Status validateFlow(Flow flow) { Match m = flow.getMatch(); boolean isIPEthertypeSet = m.isPresent(MatchType.DL_TYPE) && (m.getField(MatchType.DL_TYPE).getValue().equals(EtherTypes.IPv4.shortValue()) || m .getField(MatchType.DL_TYPE).getValue().equals(EtherTypes.IPv6.shortValue())); // network address check if ((m.isPresent(MatchType.NW_SRC) || m.isPresent(MatchType.NW_DST)) && !isIPEthertypeSet) { return new Status(StatusCode.NOTACCEPTABLE, "The match on network source or destination address cannot be accepted if the match " + "on proper ethertype is missing"); } // transport protocol check if (m.isPresent(MatchType.NW_PROTO) && !isIPEthertypeSet) { return new Status(StatusCode.NOTACCEPTABLE, "The match on network protocol cannot be accepted if the match on proper ethertype is missing"); } // transport ports check if ((m.isPresent(MatchType.TP_SRC) || m.isPresent(MatchType.TP_DST)) && (!isIPEthertypeSet || m.isAny(MatchType.NW_PROTO))) { return new Status( StatusCode.NOTACCEPTABLE, "The match on transport source or destination port cannot be accepted if the match on network protocol and match on IP ethertype are missing"); } return new Status(StatusCode.SUCCESS); }
if (!this.intersetcs(other)) { return null; if (this.getMatches() == 0) { return other.clone(); if (other.getMatches() == 0) { return this.clone(); Match intersection = new Match(); for (MatchType type : MatchType.values()) { if (this.isAny(type) && other.isAny(type)) { continue; if (this.isAny(type)) { 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(); .getSubnetMaskLength(otherMask); if (thisMaskLen < otherMaskLen) { intersection.setField(new MatchField(type, NetUtils.getSubnetPrefix(otherAddress, otherMaskLen),
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; }
Match match = new Match(); List<Action> actions = new ArrayList<Action>(); match.setField(MatchType.DL_TYPE, EtherTypes.IPv4.shortValue()); match.setField(MatchType.NW_DST, host.getNetworkAddress()); match.setField(MatchType.IN_PORT, inPort); " {}/{}", new Object[] {tag, currNode, inPort}); match.setField(MatchType.DL_VLAN, tag); } else { log.debug("No tag assigned to switch {}", currNode); outPort, currNode}); if ((removed_po != null) && (!po.getFlow().getMatch().equals( removed_po.getFlow().getMatch()))) { log.debug("Old Flow match: {}, New Flow match: {}",
private static void fillFrom(Match target, IpMatch ipMatch) { if (ipMatch != null) { Short ipProtocol = ipMatch.getIpProtocol(); if (ipProtocol != null && target.getField(NW_PROTO) == null) { target.setField(NW_PROTO, ipProtocol.byteValue()); } Dscp dscp = ipMatch.getIpDscp(); if (dscp != null) { Short dscpValue = dscp.getValue(); if (dscpValue != null) { target.setField(NW_TOS, dscpValue.byteValue()); } } } }
/** * Returns the Match object containing this packet and its payload * encapsulated packets' header fields * * @return The Match containing the header fields of this packet and of its * payload encapsulated packets */ public Match getMatch() { Match match = new Match(); Packet packet = this; while (packet != null) { packet.populateMatch(match); packet = packet.getPayload(); } return match; } }
if (this.getMatches() == 0 || other.getMatches() == 0) { return true; if (this.isAny(type) || other.isAny(type)) { continue; MatchField thisField = this.getField(type); MatchField otherField = other.getField(type);
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((match == null) ? 0 : match.hashCode()); return result; }
private static MacAddress ethernetSourceAddress(final Match sourceMatch) { final MatchField dataLinkSource = sourceMatch.getField(DL_SRC); if (dataLinkSource != null && dataLinkSource.getValue() != null) { return MDFlowMapping.toMacAddress((byte[])dataLinkSource.getValue()); } return null; }
private static void fillFrom(Match target, EthernetMatch source) { if (source == null) return; EthernetType ethType = source.getEthernetType(); if (ethType != null) { EtherType ethInnerType = ethType.getType(); if (ethInnerType != null && target.getField(DL_TYPE) == null) { Long value = ethInnerType.getValue(); target.setField(DL_TYPE, value.shortValue()); } } MacAddressFilter ethSource = source.getEthernetSource(); if (ethSource != null) { target.setField(DL_SRC, bytesFrom(ethSource.getAddress())); } MacAddressFilter ethDest = source.getEthernetDestination(); if (ethDest != null) { target.setField(DL_DST, bytesFrom(ethDest.getAddress())); } }
public static Match toMatch(org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.Match source) { Match target = new Match(); if (source != null) { fillFrom(target, source.getVlanMatch()); fillFrom(target, source.getEthernetMatch()); fillFrom(target, source.getLayer3Match()); fillFrom(target, source.getLayer4Match()); fillFrom(target, source.getIpMatch()); fillFrom(target, source.getInPort()); } return target; }
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((actions == null) ? 0 : actions.hashCode()); result = prime * result + hardTimeout; result = prime * result + (int) (id ^ (id >>> 32)); result = prime * result + idleTimeout; result = prime * result + ((match == null) ? 0 : match.hashCode()); result = prime * result + priority; return result; }
Match match = new Match(); match.setField(MatchType.IN_PORT, port); match.setField(MatchType.DL_SRC, srcMac); match.setField(MatchType.DL_DST, dstMac); match.setField(MatchType.DL_TYPE, ethertype); match.setField(MatchType.DL_VLAN, vlan); match.setField(MatchType.DL_VLAN_PR, vlanPr); match.setField(MatchType.NW_SRC, srcIP, ipMask); match.setField(MatchType.NW_DST, dstIP, ipMask2); match.setField(MatchType.NW_TOS, tos); match.setField(MatchType.NW_PROTO, proto); match.setField(MatchType.TP_SRC, src); match.setField(MatchType.TP_DST, dst);
if (match.isPresent(MatchType.DL_DST)) dst = match.getField(MatchType.DL_DST); else if (match.isPresent(MatchType.NW_DST)) dst = match.getField(MatchType.NW_DST); else return null; if (match.isPresent(MatchType.DL_DST)) { String dstMac = MatchType.DL_DST.stringify(dst.getValue()); String hostMac = ((EthernetAddress) h.getDataLayerAddress()).getMacAddress(); else if (match.isPresent(MatchType.NW_DST)) { InetAddress hostIP = h.getNetworkAddress(); if (dst.getValue().equals(hostIP)) {