3 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
5 * This program and the accompanying materials are made available under the
6 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7 * and is available at http://www.eclipse.org/legal/epl-v10.html
10 package org.opendaylight.controller.sal.core;
12 import java.io.Serializable;
14 import org.opendaylight.controller.sal.action.Action;
15 import org.opendaylight.controller.sal.action.SetDlType;
16 import org.opendaylight.controller.sal.action.SetNwDst;
17 import org.opendaylight.controller.sal.action.SetNwSrc;
18 import org.opendaylight.controller.sal.action.SetTpDst;
19 import org.opendaylight.controller.sal.action.SetTpSrc;
20 import org.opendaylight.controller.sal.flowprogrammer.Flow;
21 import org.opendaylight.controller.sal.match.Match;
22 import org.opendaylight.controller.sal.match.MatchType;
25 * Express a container flow
30 public class ContainerFlow implements Serializable {
31 private static final long serialVersionUID = 1L;
34 public ContainerFlow(Match match) {
39 * Returns a copy of the Match defined by this Container Flow
43 public Match getMatch() {
48 public int hashCode() {
51 result = prime * result + ((match == null) ? 0 : match.hashCode());
56 public boolean equals(Object obj) {
61 if (getClass() != obj.getClass())
63 ContainerFlow other = (ContainerFlow) obj;
65 if (other.match != null)
67 } else if (!match.equals(other.match))
73 public String toString() {
74 return "Container Flow [" + match.toString() + "]";
78 * Returns whether the specified flow is allowed
80 * @return true if the flow is allowed, false otherwise
82 public boolean allowsFlow(Flow flow) {
83 Match target = flow.getMatch();
85 // Check if flow's match is allowed
86 if (!this.allowsMatch(target)) {
90 // Now check if the flow's actions are not allowed
91 // Create a Match which summarizes the list of actions
92 if (flow.getActions() == null) {
95 Match actionMatch = new Match();
96 for (Action action : flow.getActions()) {
97 switch (action.getType()) {
99 actionMatch.setField(MatchType.DL_TYPE,
100 ((Integer) ((SetDlType) action).getDlType())
104 actionMatch.setField(MatchType.NW_SRC, ((SetNwSrc) action)
108 actionMatch.setField(MatchType.NW_DST, ((SetNwDst) action)
112 actionMatch.setField(MatchType.TP_SRC,
113 ((Integer) ((SetTpSrc) action).getPort()).shortValue());
116 actionMatch.setField(MatchType.TP_DST,
117 ((Integer) ((SetTpDst) action).getPort()).shortValue());
120 // This action cannot conflict
124 return this.allowsMatch(actionMatch);
128 * Returns whether the specified match is allowed
130 * @param match the match to test
131 * @return true if the match is allowed, false otherwise
133 public boolean allowsMatch(Match target) {
134 return !target.conflictWithFilter(this.match);