Thomas Vachuska | 83e090e | 2014-10-22 14:25:35 -0700 | [diff] [blame^] | 1 | /* |
| 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 | */ |
alshabib | ca5706c | 2014-10-04 20:29:41 -0700 | [diff] [blame] | 19 | package org.onlab.onos.net.flow; |
| 20 | |
| 21 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 22 | import static org.slf4j.LoggerFactory.getLogger; |
| 23 | |
| 24 | import org.onlab.onos.net.DeviceId; |
| 25 | import org.slf4j.Logger; |
| 26 | |
Yuta HIGUCHI | f6f50a6 | 2014-10-19 15:58:49 -0700 | [diff] [blame] | 27 | public class DefaultFlowEntry extends DefaultFlowRule |
| 28 | implements FlowEntry, StoredFlowEntry { |
alshabib | ca5706c | 2014-10-04 20:29:41 -0700 | [diff] [blame] | 29 | |
Yuta HIGUCHI | 3498aab | 2014-10-17 21:05:40 -0700 | [diff] [blame] | 30 | private static final Logger log = getLogger(DefaultFlowEntry.class); |
alshabib | ca5706c | 2014-10-04 20:29:41 -0700 | [diff] [blame] | 31 | |
| 32 | private long life; |
| 33 | private long packets; |
| 34 | private long bytes; |
| 35 | private FlowEntryState state; |
| 36 | |
| 37 | private long lastSeen = -1; |
| 38 | |
alshabib | 193525b | 2014-10-08 18:58:03 -0700 | [diff] [blame] | 39 | private final int errType; |
| 40 | |
| 41 | private final int errCode; |
| 42 | |
alshabib | ca5706c | 2014-10-04 20:29:41 -0700 | [diff] [blame] | 43 | |
| 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 Hart | bc4a793 | 2014-10-21 11:46:00 -0700 | [diff] [blame] | 48 | super(deviceId, selector, treatment, priority, flowId, timeout, false); |
alshabib | ca5706c | 2014-10-04 20:29:41 -0700 | [diff] [blame] | 49 | this.state = state; |
| 50 | this.life = life; |
| 51 | this.packets = packets; |
| 52 | this.bytes = bytes; |
alshabib | 193525b | 2014-10-08 18:58:03 -0700 | [diff] [blame] | 53 | this.errCode = -1; |
| 54 | this.errType = -1; |
alshabib | ca5706c | 2014-10-04 20:29:41 -0700 | [diff] [blame] | 55 | 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; |
alshabib | 193525b | 2014-10-08 18:58:03 -0700 | [diff] [blame] | 65 | this.errCode = -1; |
| 66 | this.errType = -1; |
alshabib | ca5706c | 2014-10-04 20:29:41 -0700 | [diff] [blame] | 67 | 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; |
alshabib | 193525b | 2014-10-08 18:58:03 -0700 | [diff] [blame] | 76 | this.errCode = -1; |
| 77 | this.errType = -1; |
alshabib | ca5706c | 2014-10-04 20:29:41 -0700 | [diff] [blame] | 78 | this.lastSeen = System.currentTimeMillis(); |
| 79 | } |
| 80 | |
alshabib | 193525b | 2014-10-08 18:58:03 -0700 | [diff] [blame] | 81 | 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 | |
alshabib | ca5706c | 2014-10-04 20:29:41 -0700 | [diff] [blame] | 88 | @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 |
alshabib | 193525b | 2014-10-08 18:58:03 -0700 | [diff] [blame] | 139 | public int errType() { |
| 140 | return this.errType; |
| 141 | } |
| 142 | |
| 143 | @Override |
| 144 | public int errCode() { |
| 145 | return this.errCode; |
| 146 | } |
| 147 | |
| 148 | @Override |
alshabib | ca5706c | 2014-10-04 20:29:41 -0700 | [diff] [blame] | 149 | public String toString() { |
| 150 | return toStringHelper(this) |
| 151 | .add("rule", super.toString()) |
| 152 | .add("state", state) |
| 153 | .toString(); |
| 154 | } |
| 155 | |
| 156 | |
alshabib | 193525b | 2014-10-08 18:58:03 -0700 | [diff] [blame] | 157 | |
| 158 | |
alshabib | ca5706c | 2014-10-04 20:29:41 -0700 | [diff] [blame] | 159 | } |