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.action.SetVlanId;
21 import org.opendaylight.controller.sal.flowprogrammer.Flow;
22 import org.opendaylight.controller.sal.match.Match;
23 import org.opendaylight.controller.sal.match.MatchType;
26 * Express a container flow
32 public class ContainerFlow implements Serializable {
33 private static final long serialVersionUID = 1L;
36 public ContainerFlow(Match match) {
41 * Returns a copy of the Match defined by this Container Flow
45 public Match getMatch() {
50 public int hashCode() {
53 result = prime * result + ((match == null) ? 0 : match.hashCode());
58 public boolean equals(Object obj) {
65 if (getClass() != obj.getClass()) {
68 ContainerFlow other = (ContainerFlow) obj;
70 if (other.match != null) {
73 } else if (!match.equals(other.match)) {
80 public String toString() {
81 return "Container Flow [" + match.toString() + "]";
85 * Returns whether the specified flow is allowed
87 * @return true if the flow is allowed, false otherwise
89 public boolean allowsFlow(Flow flow) {
90 Match target = flow.getMatch();
92 // Check if flow's match is allowed
93 if (!this.allowsMatch(target)) {
97 // Now check if the flow's actions are not allowed
98 // Create a Match which summarizes the list of actions
99 if (flow.getActions() == null) {
102 Match actionMatch = new Match();
103 for (Action action : flow.getActions()) {
104 switch (action.getType()) {
106 actionMatch.setField(MatchType.DL_VLAN,
107 ((Integer) ((SetVlanId) action).getVlanId())
111 actionMatch.setField(MatchType.DL_TYPE,
112 ((Integer) ((SetDlType) action).getDlType())
116 actionMatch.setField(MatchType.NW_SRC, ((SetNwSrc) action)
120 actionMatch.setField(MatchType.NW_DST, ((SetNwDst) action)
124 actionMatch.setField(MatchType.TP_SRC,
125 ((Integer) ((SetTpSrc) action).getPort()).shortValue());
128 actionMatch.setField(MatchType.TP_DST,
129 ((Integer) ((SetTpDst) action).getPort()).shortValue());
132 // This action cannot conflict
136 return this.allowsMatch(actionMatch);
140 * Returns whether the specified match is allowed
142 * @param match the match to test
143 * @return true if the match is allowed, false otherwise
145 public boolean allowsMatch(Match target) {
146 return !target.conflictWithFilter(this.match);