Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame] | 1 | /* |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 2 | * Copyright 2014 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 | |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 21 | import org.onosproject.net.DeviceId; |
alshabib | ca5706c | 2014-10-04 20:29:41 -0700 | [diff] [blame] | 22 | import org.slf4j.Logger; |
| 23 | |
Yuta HIGUCHI | f6f50a6 | 2014-10-19 15:58:49 -0700 | [diff] [blame] | 24 | public class DefaultFlowEntry extends DefaultFlowRule |
| 25 | implements FlowEntry, StoredFlowEntry { |
alshabib | ca5706c | 2014-10-04 20:29:41 -0700 | [diff] [blame] | 26 | |
Yuta HIGUCHI | 3498aab | 2014-10-17 21:05:40 -0700 | [diff] [blame] | 27 | private static final Logger log = getLogger(DefaultFlowEntry.class); |
alshabib | ca5706c | 2014-10-04 20:29:41 -0700 | [diff] [blame] | 28 | |
| 29 | private long life; |
| 30 | private long packets; |
| 31 | private long bytes; |
| 32 | private FlowEntryState state; |
| 33 | |
| 34 | private long lastSeen = -1; |
| 35 | |
alshabib | 193525b | 2014-10-08 18:58:03 -0700 | [diff] [blame] | 36 | private final int errType; |
| 37 | |
| 38 | private final int errCode; |
| 39 | |
alshabib | ca5706c | 2014-10-04 20:29:41 -0700 | [diff] [blame] | 40 | |
| 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 Hart | bc4a793 | 2014-10-21 11:46:00 -0700 | [diff] [blame] | 45 | super(deviceId, selector, treatment, priority, flowId, timeout, false); |
alshabib | ca5706c | 2014-10-04 20:29:41 -0700 | [diff] [blame] | 46 | this.state = state; |
| 47 | this.life = life; |
| 48 | this.packets = packets; |
| 49 | this.bytes = bytes; |
alshabib | 193525b | 2014-10-08 18:58:03 -0700 | [diff] [blame] | 50 | this.errCode = -1; |
| 51 | this.errType = -1; |
alshabib | ca5706c | 2014-10-04 20:29:41 -0700 | [diff] [blame] | 52 | 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; |
alshabib | 193525b | 2014-10-08 18:58:03 -0700 | [diff] [blame] | 62 | this.errCode = -1; |
| 63 | this.errType = -1; |
alshabib | ca5706c | 2014-10-04 20:29:41 -0700 | [diff] [blame] | 64 | 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; |
alshabib | 193525b | 2014-10-08 18:58:03 -0700 | [diff] [blame] | 73 | this.errCode = -1; |
| 74 | this.errType = -1; |
alshabib | ca5706c | 2014-10-04 20:29:41 -0700 | [diff] [blame] | 75 | this.lastSeen = System.currentTimeMillis(); |
| 76 | } |
| 77 | |
alshabib | 193525b | 2014-10-08 18:58:03 -0700 | [diff] [blame] | 78 | 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 Milkey | 930fc66 | 2014-11-11 16:07:45 -0800 | [diff] [blame] | 83 | this.lastSeen = System.currentTimeMillis(); |
alshabib | 193525b | 2014-10-08 18:58:03 -0700 | [diff] [blame] | 84 | } |
| 85 | |
alshabib | ca5706c | 2014-10-04 20:29:41 -0700 | [diff] [blame] | 86 | @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 |
alshabib | 193525b | 2014-10-08 18:58:03 -0700 | [diff] [blame] | 137 | public int errType() { |
| 138 | return this.errType; |
| 139 | } |
| 140 | |
| 141 | @Override |
| 142 | public int errCode() { |
| 143 | return this.errCode; |
| 144 | } |
| 145 | |
| 146 | @Override |
alshabib | ca5706c | 2014-10-04 20:29:41 -0700 | [diff] [blame] | 147 | public String toString() { |
| 148 | return toStringHelper(this) |
| 149 | .add("rule", super.toString()) |
| 150 | .add("state", state) |
| 151 | .toString(); |
| 152 | } |
| 153 | |
| 154 | |
alshabib | 193525b | 2014-10-08 18:58:03 -0700 | [diff] [blame] | 155 | |
| 156 | |
alshabib | ca5706c | 2014-10-04 20:29:41 -0700 | [diff] [blame] | 157 | } |