blob: 59aed2371840c69a944b257345ce2c94eac16d16 [file] [log] [blame]
Thomas Vachuska83e090e2014-10-22 14:25:35 -07001/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
alshabibca5706c2014-10-04 20:29:41 -070019package org.onlab.onos.net.flow;
20
21import static com.google.common.base.MoreObjects.toStringHelper;
22import static org.slf4j.LoggerFactory.getLogger;
23
24import org.onlab.onos.net.DeviceId;
25import org.slf4j.Logger;
26
Yuta HIGUCHIf6f50a62014-10-19 15:58:49 -070027public class DefaultFlowEntry extends DefaultFlowRule
28 implements FlowEntry, StoredFlowEntry {
alshabibca5706c2014-10-04 20:29:41 -070029
Yuta HIGUCHI3498aab2014-10-17 21:05:40 -070030 private static final Logger log = getLogger(DefaultFlowEntry.class);
alshabibca5706c2014-10-04 20:29:41 -070031
32 private long life;
33 private long packets;
34 private long bytes;
35 private FlowEntryState state;
36
37 private long lastSeen = -1;
38
alshabib193525b2014-10-08 18:58:03 -070039 private final int errType;
40
41 private final int errCode;
42
alshabibca5706c2014-10-04 20:29:41 -070043
44 public DefaultFlowEntry(DeviceId deviceId, TrafficSelector selector,
45 TrafficTreatment treatment, int priority, FlowEntryState state,
46 long life, long packets, long bytes, long flowId,
47 int timeout) {
Jonathan Hartbc4a7932014-10-21 11:46:00 -070048 super(deviceId, selector, treatment, priority, flowId, timeout, false);
alshabibca5706c2014-10-04 20:29:41 -070049 this.state = state;
50 this.life = life;
51 this.packets = packets;
52 this.bytes = bytes;
alshabib193525b2014-10-08 18:58:03 -070053 this.errCode = -1;
54 this.errType = -1;
alshabibca5706c2014-10-04 20:29:41 -070055 this.lastSeen = System.currentTimeMillis();
56 }
57
58 public DefaultFlowEntry(FlowRule rule, FlowEntryState state,
59 long life, long packets, long bytes) {
60 super(rule);
61 this.state = state;
62 this.life = life;
63 this.packets = packets;
64 this.bytes = bytes;
alshabib193525b2014-10-08 18:58:03 -070065 this.errCode = -1;
66 this.errType = -1;
alshabibca5706c2014-10-04 20:29:41 -070067 this.lastSeen = System.currentTimeMillis();
68 }
69
70 public DefaultFlowEntry(FlowRule rule) {
71 super(rule);
72 this.state = FlowEntryState.PENDING_ADD;
73 this.life = 0;
74 this.packets = 0;
75 this.bytes = 0;
alshabib193525b2014-10-08 18:58:03 -070076 this.errCode = -1;
77 this.errType = -1;
alshabibca5706c2014-10-04 20:29:41 -070078 this.lastSeen = System.currentTimeMillis();
79 }
80
alshabib193525b2014-10-08 18:58:03 -070081 public DefaultFlowEntry(FlowRule rule, int errType, int errCode) {
82 super(rule);
83 this.state = FlowEntryState.FAILED;
84 this.errType = errType;
85 this.errCode = errCode;
86 }
87
alshabibca5706c2014-10-04 20:29:41 -070088 @Override
89 public long life() {
90 return life;
91 }
92
93 @Override
94 public long packets() {
95 return packets;
96 }
97
98 @Override
99 public long bytes() {
100 return bytes;
101 }
102
103 @Override
104 public FlowEntryState state() {
105 return this.state;
106 }
107
108 @Override
109 public long lastSeen() {
110 return lastSeen;
111 }
112
113 @Override
114 public void setLastSeen() {
115 this.lastSeen = System.currentTimeMillis();
116 }
117
118 @Override
119 public void setState(FlowEntryState newState) {
120 this.state = newState;
121 }
122
123 @Override
124 public void setLife(long life) {
125 this.life = life;
126 }
127
128 @Override
129 public void setPackets(long packets) {
130 this.packets = packets;
131 }
132
133 @Override
134 public void setBytes(long bytes) {
135 this.bytes = bytes;
136 }
137
138 @Override
alshabib193525b2014-10-08 18:58:03 -0700139 public int errType() {
140 return this.errType;
141 }
142
143 @Override
144 public int errCode() {
145 return this.errCode;
146 }
147
148 @Override
alshabibca5706c2014-10-04 20:29:41 -0700149 public String toString() {
150 return toStringHelper(this)
151 .add("rule", super.toString())
152 .add("state", state)
153 .toString();
154 }
155
156
alshabib193525b2014-10-08 18:58:03 -0700157
158
alshabibca5706c2014-10-04 20:29:41 -0700159}