Mark AD-SAL interfaces as deprecated
[controller.git] / opendaylight / adsal / sal / api / src / main / java / org / opendaylight / controller / sal / core / ContainerFlow.java
1
2 /*
3  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
4  *
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
8  */
9
10 package org.opendaylight.controller.sal.core;
11
12 import java.io.Serializable;
13
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;
24
25 /**
26  * Express a container flow
27  *
28  *
29  *
30  */
31 @Deprecated
32 public class ContainerFlow implements Serializable {
33     private static final long serialVersionUID = 1L;
34     private Match match;
35
36     public ContainerFlow(Match match) {
37         this.match = match;
38     }
39
40     /**
41      * Returns a copy of the Match defined by this Container Flow
42      *
43      * @return Match
44      */
45     public Match getMatch() {
46         return match.clone();
47     }
48
49     @Override
50     public int hashCode() {
51         final int prime = 31;
52         int result = 1;
53         result = prime * result + ((match == null) ? 0 : match.hashCode());
54         return result;
55     }
56
57     @Override
58     public boolean equals(Object obj) {
59         if (this == obj) {
60             return true;
61         }
62         if (obj == null) {
63             return false;
64         }
65         if (getClass() != obj.getClass()) {
66             return false;
67         }
68         ContainerFlow other = (ContainerFlow) obj;
69         if (match == null) {
70             if (other.match != null) {
71                 return false;
72             }
73         } else if (!match.equals(other.match)) {
74             return false;
75         }
76         return true;
77     }
78
79     @Override
80     public String toString() {
81         return "Container Flow [" + match.toString() + "]";
82     }
83
84     /**
85      * Returns whether the specified flow is allowed
86      *
87      * @return true if the flow is allowed, false otherwise
88      */
89     public boolean allowsFlow(Flow flow) {
90         Match target = flow.getMatch();
91
92         // Check if flow's match is allowed
93         if (!this.allowsMatch(target)) {
94             return false;
95         }
96
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) {
100             return true;
101         }
102         Match actionMatch = new Match();
103         for (Action action : flow.getActions()) {
104             switch (action.getType()) {
105             case SET_VLAN_ID:
106                 actionMatch.setField(MatchType.DL_VLAN,
107                         ((Integer) ((SetVlanId) action).getVlanId())
108                                 .shortValue());
109                 break;
110             case SET_DL_TYPE:
111                 actionMatch.setField(MatchType.DL_TYPE,
112                         ((Integer) ((SetDlType) action).getDlType())
113                                 .shortValue());
114                 break;
115             case SET_NW_SRC:
116                 actionMatch.setField(MatchType.NW_SRC, ((SetNwSrc) action)
117                         .getAddress());
118                 break;
119             case SET_NW_DST:
120                 actionMatch.setField(MatchType.NW_DST, ((SetNwDst) action)
121                         .getAddress());
122                 break;
123             case SET_TP_SRC:
124                 actionMatch.setField(MatchType.TP_SRC,
125                         ((Integer) ((SetTpSrc) action).getPort()).shortValue());
126                 break;
127             case SET_TP_DST:
128                 actionMatch.setField(MatchType.TP_DST,
129                         ((Integer) ((SetTpDst) action).getPort()).shortValue());
130                 break;
131             default:
132                 // This action cannot conflict
133             }
134         }
135
136         return this.allowsMatch(actionMatch);
137     }
138
139     /**
140      * Returns whether the specified match is allowed
141      *
142      * @param match the match to test
143      * @return true if the match is allowed, false otherwise
144      */
145     public boolean allowsMatch(Match target) {
146         return !target.conflictWithFilter(this.match);
147     }
148 }