blob: dbd5e08a6a7e07652e3f94528b69cd14f479248e [file] [log] [blame]
Thomas Vachuska83e090e2014-10-22 14:25:35 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2014-present 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
alshabibca5706c2014-10-04 20:29:41 -070021import org.slf4j.Logger;
22
Yuta HIGUCHIf6f50a62014-10-19 15:58:49 -070023public class DefaultFlowEntry extends DefaultFlowRule
Madan Jampani54d34992015-03-06 17:27:52 -080024 implements StoredFlowEntry {
alshabibca5706c2014-10-04 20:29:41 -070025
Yuta HIGUCHI3498aab2014-10-17 21:05:40 -070026 private static final Logger log = getLogger(DefaultFlowEntry.class);
alshabibca5706c2014-10-04 20:29:41 -070027
28 private long life;
29 private long packets;
30 private long bytes;
31 private FlowEntryState state;
32
33 private long lastSeen = -1;
34
alshabib193525b2014-10-08 18:58:03 -070035 private final int errType;
36
37 private final int errCode;
38
alshabibca5706c2014-10-04 20:29:41 -070039 public DefaultFlowEntry(FlowRule rule, FlowEntryState state,
40 long life, long packets, long bytes) {
41 super(rule);
42 this.state = state;
43 this.life = life;
44 this.packets = packets;
45 this.bytes = bytes;
alshabib193525b2014-10-08 18:58:03 -070046 this.errCode = -1;
47 this.errType = -1;
alshabibca5706c2014-10-04 20:29:41 -070048 this.lastSeen = System.currentTimeMillis();
49 }
50
51 public DefaultFlowEntry(FlowRule rule) {
52 super(rule);
53 this.state = FlowEntryState.PENDING_ADD;
54 this.life = 0;
55 this.packets = 0;
56 this.bytes = 0;
alshabib193525b2014-10-08 18:58:03 -070057 this.errCode = -1;
58 this.errType = -1;
alshabibca5706c2014-10-04 20:29:41 -070059 this.lastSeen = System.currentTimeMillis();
60 }
61
alshabib193525b2014-10-08 18:58:03 -070062 public DefaultFlowEntry(FlowRule rule, int errType, int errCode) {
63 super(rule);
64 this.state = FlowEntryState.FAILED;
65 this.errType = errType;
66 this.errCode = errCode;
Ray Milkey930fc662014-11-11 16:07:45 -080067 this.lastSeen = System.currentTimeMillis();
alshabib193525b2014-10-08 18:58:03 -070068 }
69
alshabibca5706c2014-10-04 20:29:41 -070070 @Override
71 public long life() {
72 return life;
73 }
74
75 @Override
76 public long packets() {
77 return packets;
78 }
79
80 @Override
81 public long bytes() {
82 return bytes;
83 }
84
85 @Override
86 public FlowEntryState state() {
87 return this.state;
88 }
89
90 @Override
91 public long lastSeen() {
92 return lastSeen;
93 }
94
95 @Override
96 public void setLastSeen() {
97 this.lastSeen = System.currentTimeMillis();
98 }
99
100 @Override
101 public void setState(FlowEntryState newState) {
102 this.state = newState;
103 }
104
105 @Override
106 public void setLife(long life) {
107 this.life = life;
108 }
109
110 @Override
111 public void setPackets(long packets) {
112 this.packets = packets;
113 }
114
115 @Override
116 public void setBytes(long bytes) {
117 this.bytes = bytes;
118 }
119
120 @Override
alshabib193525b2014-10-08 18:58:03 -0700121 public int errType() {
122 return this.errType;
123 }
124
125 @Override
126 public int errCode() {
127 return this.errCode;
128 }
129
130 @Override
alshabibca5706c2014-10-04 20:29:41 -0700131 public String toString() {
132 return toStringHelper(this)
133 .add("rule", super.toString())
134 .add("state", state)
135 .toString();
136 }
alshabibca5706c2014-10-04 20:29:41 -0700137}