Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Laboratory |
Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 3 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 4 | * 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 Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 7 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 8 | * 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 Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 15 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.net.flow; |
alshabib | ca5706c | 2014-10-04 20:29:41 -0700 | [diff] [blame] | 17 | |
| 18 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 19 | import static org.slf4j.LoggerFactory.getLogger; |
| 20 | |
alshabib | ca5706c | 2014-10-04 20:29:41 -0700 | [diff] [blame] | 21 | import org.slf4j.Logger; |
| 22 | |
Yuta HIGUCHI | f6f50a6 | 2014-10-19 15:58:49 -0700 | [diff] [blame] | 23 | public class DefaultFlowEntry extends DefaultFlowRule |
Madan Jampani | 54d3499 | 2015-03-06 17:27:52 -0800 | [diff] [blame] | 24 | implements StoredFlowEntry { |
alshabib | ca5706c | 2014-10-04 20:29:41 -0700 | [diff] [blame] | 25 | |
Yuta HIGUCHI | 3498aab | 2014-10-17 21:05:40 -0700 | [diff] [blame] | 26 | private static final Logger log = getLogger(DefaultFlowEntry.class); |
alshabib | ca5706c | 2014-10-04 20:29:41 -0700 | [diff] [blame] | 27 | |
| 28 | private long life; |
| 29 | private long packets; |
| 30 | private long bytes; |
| 31 | private FlowEntryState state; |
| 32 | |
| 33 | private long lastSeen = -1; |
| 34 | |
alshabib | 193525b | 2014-10-08 18:58:03 -0700 | [diff] [blame] | 35 | private final int errType; |
| 36 | |
| 37 | private final int errCode; |
| 38 | |
alshabib | ca5706c | 2014-10-04 20:29:41 -0700 | [diff] [blame] | 39 | 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; |
alshabib | 193525b | 2014-10-08 18:58:03 -0700 | [diff] [blame] | 46 | this.errCode = -1; |
| 47 | this.errType = -1; |
alshabib | ca5706c | 2014-10-04 20:29:41 -0700 | [diff] [blame] | 48 | 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; |
alshabib | 193525b | 2014-10-08 18:58:03 -0700 | [diff] [blame] | 57 | this.errCode = -1; |
| 58 | this.errType = -1; |
alshabib | ca5706c | 2014-10-04 20:29:41 -0700 | [diff] [blame] | 59 | this.lastSeen = System.currentTimeMillis(); |
| 60 | } |
| 61 | |
alshabib | 193525b | 2014-10-08 18:58:03 -0700 | [diff] [blame] | 62 | 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 Milkey | 930fc66 | 2014-11-11 16:07:45 -0800 | [diff] [blame] | 67 | this.lastSeen = System.currentTimeMillis(); |
alshabib | 193525b | 2014-10-08 18:58:03 -0700 | [diff] [blame] | 68 | } |
| 69 | |
alshabib | ca5706c | 2014-10-04 20:29:41 -0700 | [diff] [blame] | 70 | @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 |
alshabib | 193525b | 2014-10-08 18:58:03 -0700 | [diff] [blame] | 121 | public int errType() { |
| 122 | return this.errType; |
| 123 | } |
| 124 | |
| 125 | @Override |
| 126 | public int errCode() { |
| 127 | return this.errCode; |
| 128 | } |
| 129 | |
| 130 | @Override |
alshabib | ca5706c | 2014-10-04 20:29:41 -0700 | [diff] [blame] | 131 | public String toString() { |
| 132 | return toStringHelper(this) |
| 133 | .add("rule", super.toString()) |
| 134 | .add("state", state) |
| 135 | .toString(); |
| 136 | } |
alshabib | ca5706c | 2014-10-04 20:29:41 -0700 | [diff] [blame] | 137 | } |