blob: e46e3dfb6565cbe7dfa3dbacf0dc1f13245a2e1f [file] [log] [blame]
Thomas Vachuska83e090e2014-10-22 14:25:35 -07001/*
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07002 * Copyright 2014 Open Networking Laboratory
Thomas Vachuska83e090e2014-10-22 14:25:35 -07003 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07004 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
Thomas Vachuska83e090e2014-10-22 14:25:35 -07007 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07008 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
Thomas Vachuska83e090e2014-10-22 14:25:35 -070015 */
Brian O'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.net.flow;
alshabibca5706c2014-10-04 20:29:41 -070017
18import static com.google.common.base.MoreObjects.toStringHelper;
19import static org.slf4j.LoggerFactory.getLogger;
20
Brian O'Connorabafb502014-12-02 22:26:20 -080021import org.onosproject.net.DeviceId;
alshabibca5706c2014-10-04 20:29:41 -070022import org.slf4j.Logger;
23
Yuta HIGUCHIf6f50a62014-10-19 15:58:49 -070024public class DefaultFlowEntry extends DefaultFlowRule
25 implements FlowEntry, StoredFlowEntry {
alshabibca5706c2014-10-04 20:29:41 -070026
Yuta HIGUCHI3498aab2014-10-17 21:05:40 -070027 private static final Logger log = getLogger(DefaultFlowEntry.class);
alshabibca5706c2014-10-04 20:29:41 -070028
29 private long life;
30 private long packets;
31 private long bytes;
32 private FlowEntryState state;
33
34 private long lastSeen = -1;
35
alshabib193525b2014-10-08 18:58:03 -070036 private final int errType;
37
38 private final int errCode;
39
alshabibca5706c2014-10-04 20:29:41 -070040
41 public DefaultFlowEntry(DeviceId deviceId, TrafficSelector selector,
42 TrafficTreatment treatment, int priority, FlowEntryState state,
43 long life, long packets, long bytes, long flowId,
44 int timeout) {
Jonathan Hartbc4a7932014-10-21 11:46:00 -070045 super(deviceId, selector, treatment, priority, flowId, timeout, false);
alshabibca5706c2014-10-04 20:29:41 -070046 this.state = state;
47 this.life = life;
48 this.packets = packets;
49 this.bytes = bytes;
alshabib193525b2014-10-08 18:58:03 -070050 this.errCode = -1;
51 this.errType = -1;
alshabibca5706c2014-10-04 20:29:41 -070052 this.lastSeen = System.currentTimeMillis();
53 }
54
55 public DefaultFlowEntry(FlowRule rule, FlowEntryState state,
56 long life, long packets, long bytes) {
57 super(rule);
58 this.state = state;
59 this.life = life;
60 this.packets = packets;
61 this.bytes = bytes;
alshabib193525b2014-10-08 18:58:03 -070062 this.errCode = -1;
63 this.errType = -1;
alshabibca5706c2014-10-04 20:29:41 -070064 this.lastSeen = System.currentTimeMillis();
65 }
66
67 public DefaultFlowEntry(FlowRule rule) {
68 super(rule);
69 this.state = FlowEntryState.PENDING_ADD;
70 this.life = 0;
71 this.packets = 0;
72 this.bytes = 0;
alshabib193525b2014-10-08 18:58:03 -070073 this.errCode = -1;
74 this.errType = -1;
alshabibca5706c2014-10-04 20:29:41 -070075 this.lastSeen = System.currentTimeMillis();
76 }
77
alshabib193525b2014-10-08 18:58:03 -070078 public DefaultFlowEntry(FlowRule rule, int errType, int errCode) {
79 super(rule);
80 this.state = FlowEntryState.FAILED;
81 this.errType = errType;
82 this.errCode = errCode;
Ray Milkey930fc662014-11-11 16:07:45 -080083 this.lastSeen = System.currentTimeMillis();
alshabib193525b2014-10-08 18:58:03 -070084 }
85
alshabibca5706c2014-10-04 20:29:41 -070086 @Override
87 public long life() {
88 return life;
89 }
90
91 @Override
92 public long packets() {
93 return packets;
94 }
95
96 @Override
97 public long bytes() {
98 return bytes;
99 }
100
101 @Override
102 public FlowEntryState state() {
103 return this.state;
104 }
105
106 @Override
107 public long lastSeen() {
108 return lastSeen;
109 }
110
111 @Override
112 public void setLastSeen() {
113 this.lastSeen = System.currentTimeMillis();
114 }
115
116 @Override
117 public void setState(FlowEntryState newState) {
118 this.state = newState;
119 }
120
121 @Override
122 public void setLife(long life) {
123 this.life = life;
124 }
125
126 @Override
127 public void setPackets(long packets) {
128 this.packets = packets;
129 }
130
131 @Override
132 public void setBytes(long bytes) {
133 this.bytes = bytes;
134 }
135
136 @Override
alshabib193525b2014-10-08 18:58:03 -0700137 public int errType() {
138 return this.errType;
139 }
140
141 @Override
142 public int errCode() {
143 return this.errCode;
144 }
145
146 @Override
alshabibca5706c2014-10-04 20:29:41 -0700147 public String toString() {
148 return toStringHelper(this)
149 .add("rule", super.toString())
150 .add("state", state)
151 .toString();
152 }
153
154
alshabib193525b2014-10-08 18:58:03 -0700155
156
alshabibca5706c2014-10-04 20:29:41 -0700157}