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); }
/** * 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); }
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 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)) {
/** * 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; }
protected Host getSourceHostFromFlow(Flow flow, Set<HostNodeConnector> hosts) { Host srcHost = null; Match match = flow.getMatch(); // Flow must have IN_PORT field (DL_SRC rarely (never?) // exists). if (match.isPresent(MatchType.IN_PORT)) { MatchField inPort = match.getField(MatchType.IN_PORT); // Check cache Host cacheHit = this.sourceHostCache.get(inPort); if (cacheHit != null) return cacheHit; // Find the source host by comparing the NodeConnectors NodeConnector inPortNc = (NodeConnector) inPort.getValue(); for (HostNodeConnector h : hosts) { NodeConnector hostNc = h.getnodeConnector(); if (hostNc.equals(inPortNc)) { srcHost = h; this.sourceHostCache.put(inPort, h); // Add to cache break; } } } return srcHost; }
private void handleFlowRemovedMessage(ISwitch sw, OFFlowRemoved msg) { Node node = NodeCreator.createOFNode(sw.getId()); Flow flow = new FlowConverter(msg.getMatch(), new ArrayList<OFAction>(0)).getFlow(node); flow.setPriority(msg.getPriority()); flow.setIdleTimeout(msg.getIdleTimeout()); flow.setId(msg.getCookie()); Match match = flow.getMatch(); NodeConnector inPort = match.isPresent(MatchType.IN_PORT) ? (NodeConnector) match .getField(MatchType.IN_PORT).getValue() : null; for (Map.Entry<String, IFlowProgrammerNotifier> containerNotifier : flowProgrammerNotifiers .entrySet()) { String container = containerNotifier.getKey(); IFlowProgrammerNotifier notifier = containerNotifier.getValue(); /* * Switch only provide us with the match information. For now let's * try to identify the container membership only from the input port * match field. In any case, upper layer consumers can derive * whether the notification was not for them. More sophisticated * filtering can be added later on. */ if (inPort == null || container.equals(GlobalConstants.DEFAULT.toString()) || (containerToNc.containsKey(container) && containerToNc.get(container).contains(inPort))) { notifier.flowRemoved(node, flow); } } }
node.toString() : desc; row.put("nodeName", desc); if (match.isPresent(MatchType.IN_PORT)) { row.put(MatchType.IN_PORT.id(), ((NodeConnector) flow.getMatch() .getField(MatchType.IN_PORT).getValue()) if (match.isPresent(MatchType.DL_SRC)) { row.put(MatchType.DL_SRC.id(), (HexEncode.bytesToHexString(((byte[]) flow.getMatch() if (match.isPresent(MatchType.DL_DST)) { row.put(MatchType.DL_DST.id(), (HexEncode.bytesToHexString(((byte[]) flow.getMatch() if (match.isPresent(MatchType.DL_TYPE)) { row.put(MatchType.DL_TYPE.id(), EtherTypes.getEtherTypeName(((Short) flow.getMatch() if (match.isPresent(MatchType.DL_VLAN)) { if (((Short) flow.getMatch().getField(MatchType.DL_VLAN).getValue()) .shortValue() < 0) { if (match.isPresent(MatchType.DL_VLAN_PR)) { if (((Byte) flow.getMatch().getField(MatchType.DL_VLAN_PR).getValue()) .shortValue() < 0) { if (match.isPresent(MatchType.NW_SRC)) { row.put(MatchType.NW_SRC.id(), ((InetAddress) flow.getMatch() .getField(MatchType.NW_SRC).getValue()).getHostAddress());
if (match.isPresent(MatchType.IN_PORT)) { NodeConnector inputPort = (NodeConnector)match.getField(MatchType.IN_PORT).getValue(); if (!switchManager.getNodeConnectors(node).contains(inputPort)) {
private boolean doesFlowContainNodeConnector(Flow flow, NodeConnector nc) { if (nc == null) { return false; } Match match = flow.getMatch(); if (match.isPresent(MatchType.IN_PORT)) { NodeConnector matchPort = (NodeConnector) match.getField(MatchType.IN_PORT).getValue(); if (matchPort.equals(nc)) { return true; } } List<Action> actionsList = flow.getActions(); if (actionsList != null) { for (Action action : actionsList) { if (action instanceof Output) { NodeConnector actionPort = ((Output) action).getPort(); if (actionPort.equals(nc)) { return true; } } } } return false; }
if (match.isPresent(MatchType.IN_PORT)) { short port = (Short) ((NodeConnector) match.getField( MatchType.IN_PORT).getValue()).getID(); if (match.isPresent(MatchType.DL_SRC)) { byte[] srcMac = (byte[]) match.getField(MatchType.DL_SRC) .getValue(); if (match.isPresent(MatchType.DL_DST)) { byte[] dstMac = (byte[]) match.getField(MatchType.DL_DST) .getValue(); if (match.isPresent(MatchType.DL_VLAN)) { short vlan = (Short) match.getField(MatchType.DL_VLAN) .getValue(); if (match.isPresent(MatchType.DL_VLAN_PR)) { byte vlanPr = (Byte) match.getField(MatchType.DL_VLAN_PR) .getValue(); if (match.isPresent(MatchType.DL_TYPE)) { short ethType = (Short) match.getField(MatchType.DL_TYPE) .getValue(); if (match.isPresent(MatchType.NW_TOS)) { if (match.isPresent(MatchType.NW_PROTO)) { byte proto = (Byte) match.getField(MatchType.NW_PROTO) .getValue();
/** * Check whether the ports in the flow match and flow actions for * the specified node belong to the container * * @param container * @param node * @param flow * @return */ private boolean flowPortsBelongToContainer(String container, Node node, Flow flow) { Match m = flow.getMatch(); if (m.isPresent(MatchType.IN_PORT)) { NodeConnector inPort = (NodeConnector) m.getField(MatchType.IN_PORT).getValue(); // If the incoming port is specified, check if it belongs to if (!containerOwnsNodeConnector(container, inPort)) { return false; } } // If an outgoing port is specified, it must belong to this container for (Action action : flow.getActions()) { if (action.getType() == ActionType.OUTPUT) { NodeConnector outPort = ((Output) action).getPort(); if (!containerOwnsNodeConnector(container, outPort)) { return false; } } } return true; }
Flow flow) { Match m = flow.getMatch(); if (m.isPresent(MatchType.IN_PORT)) { NodeConnector inPort = (NodeConnector) m .getField(MatchType.IN_PORT).getValue();