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.apache.commons.lang3.builder.EqualsBuilder;
15 import org.apache.commons.lang3.builder.HashCodeBuilder;
16 import org.opendaylight.controller.sal.action.Action;
17 import org.opendaylight.controller.sal.action.SetDlType;
18 import org.opendaylight.controller.sal.action.SetNwDst;
19 import org.opendaylight.controller.sal.action.SetNwSrc;
20 import org.opendaylight.controller.sal.action.SetTpDst;
21 import org.opendaylight.controller.sal.action.SetTpSrc;
22 import org.opendaylight.controller.sal.flowprogrammer.Flow;
23 import org.opendaylight.controller.sal.match.Match;
24 import org.opendaylight.controller.sal.match.MatchType;
27 * 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() {
51 return HashCodeBuilder.reflectionHashCode(this);
55 public boolean equals(Object obj) {
56 return EqualsBuilder.reflectionEquals(this, obj);
60 public String toString() {
61 return "Container Flow [" + match.toString() + "]";
65 * Returns whether the specified flow is allowed
67 * @return true if the flow is allowed, false otherwise
69 public boolean allowsFlow(Flow flow) {
70 Match target = flow.getMatch();
72 // Check if flow's match is allowed
73 if (!this.allowsMatch(target)) {
77 // Now check if the flow's actions are not allowed
78 // Create a Match which summarizes the list of actions
79 if (flow.getActions() == null) {
82 Match actionMatch = new Match();
83 for (Action action : flow.getActions()) {
84 switch (action.getType()) {
86 actionMatch.setField(MatchType.DL_TYPE,
87 ((Integer) ((SetDlType) action).getDlType())
91 actionMatch.setField(MatchType.NW_SRC, ((SetNwSrc) action)
95 actionMatch.setField(MatchType.NW_DST, ((SetNwDst) action)
99 actionMatch.setField(MatchType.TP_SRC,
100 ((Integer) ((SetTpSrc) action).getPort()).shortValue());
103 actionMatch.setField(MatchType.TP_DST,
104 ((Integer) ((SetTpDst) action).getPort()).shortValue());
107 // This action cannot conflict
111 return this.allowsMatch(actionMatch);
115 * Returns whether the specified match is allowed
117 * @param match the match to test
118 * @return true if the match is allowed, false otherwise
120 public boolean allowsMatch(Match target) {
121 return !target.conflictWithFilter(this.match);