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
31 public class ContainerFlow implements Serializable {
32 private static final long serialVersionUID = 1L;
35 public ContainerFlow(Match match) {
40 * Returns a copy of the Match defined by this Container Flow
44 public Match getMatch() {
49 public int hashCode() {
52 result = prime * result + ((match == null) ? 0 : match.hashCode());
57 public boolean equals(Object obj) {
64 if (getClass() != obj.getClass()) {
67 ContainerFlow other = (ContainerFlow) obj;
69 if (other.match != null) {
72 } else if (!match.equals(other.match)) {
79 public String toString() {
80 return "Container Flow [" + match.toString() + "]";
84 * Returns whether the specified flow is allowed
86 * @return true if the flow is allowed, false otherwise
88 public boolean allowsFlow(Flow flow) {
89 Match target = flow.getMatch();
91 // Check if flow's match is allowed
92 if (!this.allowsMatch(target)) {
96 // Now check if the flow's actions are not allowed
97 // Create a Match which summarizes the list of actions
98 if (flow.getActions() == null) {
101 Match actionMatch = new Match();
102 for (Action action : flow.getActions()) {
103 switch (action.getType()) {
105 actionMatch.setField(MatchType.DL_VLAN,
106 ((Integer) ((SetVlanId) action).getVlanId())
110 actionMatch.setField(MatchType.DL_TYPE,
111 ((Integer) ((SetDlType) action).getDlType())
115 actionMatch.setField(MatchType.NW_SRC, ((SetNwSrc) action)
119 actionMatch.setField(MatchType.NW_DST, ((SetNwDst) action)
123 actionMatch.setField(MatchType.TP_SRC,
124 ((Integer) ((SetTpSrc) action).getPort()).shortValue());
127 actionMatch.setField(MatchType.TP_DST,
128 ((Integer) ((SetTpDst) action).getPort()).shortValue());
131 // This action cannot conflict
135 return this.allowsMatch(actionMatch);
139 * Returns whether the specified match is allowed
141 * @param match the match to test
142 * @return true if the match is allowed, false otherwise
144 public boolean allowsMatch(Match target) {
145 return !target.conflictWithFilter(this.match);