blob: c2d901b7a64c1f4609e3ef644a7ba7a37e2d5eb8 [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 */
alshabibca5706c2014-10-04 20:29:41 -070016package org.onlab.onos.net.flow;
17
18import static com.google.common.base.MoreObjects.toStringHelper;
19import static org.slf4j.LoggerFactory.getLogger;
20
21import org.onlab.onos.net.DeviceId;
22import 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;
83 }
84
alshabibca5706c2014-10-04 20:29:41 -070085 @Override
86 public long life() {
87 return life;
88 }
89
90 @Override
91 public long packets() {
92 return packets;
93 }
94
95 @Override
96 public long bytes() {
97 return bytes;
98 }
99
100 @Override
101 public FlowEntryState state() {
102 return this.state;
103 }
104
105 @Override
106 public long lastSeen() {
107 return lastSeen;
108 }
109
110 @Override
111 public void setLastSeen() {
112 this.lastSeen = System.currentTimeMillis();
113 }
114
115 @Override
116 public void setState(FlowEntryState newState) {
117 this.state = newState;
118 }
119
120 @Override
121 public void setLife(long life) {
122 this.life = life;
123 }
124
125 @Override
126 public void setPackets(long packets) {
127 this.packets = packets;
128 }
129
130 @Override
131 public void setBytes(long bytes) {
132 this.bytes = bytes;
133 }
134
135 @Override
alshabib193525b2014-10-08 18:58:03 -0700136 public int errType() {
137 return this.errType;
138 }
139
140 @Override
141 public int errCode() {
142 return this.errCode;
143 }
144
145 @Override
alshabibca5706c2014-10-04 20:29:41 -0700146 public String toString() {
147 return toStringHelper(this)
148 .add("rule", super.toString())
149 .add("state", state)
150 .toString();
151 }
152
153
alshabib193525b2014-10-08 18:58:03 -0700154
155
alshabibca5706c2014-10-04 20:29:41 -0700156}