Madan Jampani | c27b6b2 | 2016-02-05 11:36:31 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Laboratory |
Madan Jampani | c27b6b2 | 2016-02-05 11:36:31 -0800 | [diff] [blame] | 3 | * |
| 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 |
| 7 | * |
| 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. |
| 15 | */ |
| 16 | |
| 17 | package org.onosproject.net.flow; |
| 18 | |
Thiago Santos | 877914d | 2016-07-20 18:29:29 -0300 | [diff] [blame] | 19 | import java.util.concurrent.TimeUnit; |
| 20 | |
Madan Jampani | c27b6b2 | 2016-02-05 11:36:31 -0800 | [diff] [blame] | 21 | import static com.google.common.base.MoreObjects.toStringHelper; |
Thiago Santos | 877914d | 2016-07-20 18:29:29 -0300 | [diff] [blame] | 22 | import static java.util.concurrent.TimeUnit.NANOSECONDS; |
Madan Jampani | c27b6b2 | 2016-02-05 11:36:31 -0800 | [diff] [blame] | 23 | |
| 24 | /** |
| 25 | * Default flow entry class with FlowLiveType value, IMMEDIATE_FLOW, SHORT_FLOW, MID_FLOW, LONG_FLOW. |
| 26 | */ |
| 27 | public class DefaultTypedFlowEntry extends DefaultFlowEntry |
| 28 | implements TypedStoredFlowEntry { |
| 29 | private FlowLiveType liveType; |
| 30 | |
Thiago Santos | 877914d | 2016-07-20 18:29:29 -0300 | [diff] [blame] | 31 | |
| 32 | /** |
| 33 | * Creates a typed flow entry from flow rule and its statistics, with default flow live type(IMMEDIATE_FLOW). |
| 34 | * |
| 35 | * @param rule the flow rule |
| 36 | * @param state the flow state |
| 37 | * @param life the flow duration since creation |
| 38 | * @param lifeTimeUnit the time unit of life |
| 39 | * @param packets the flow packets count |
| 40 | * @param bytes the flow bytes count |
| 41 | */ |
| 42 | public DefaultTypedFlowEntry(FlowRule rule, FlowEntryState state, |
| 43 | long life, TimeUnit lifeTimeUnit, long packets, long bytes) { |
| 44 | super(rule, state, life, lifeTimeUnit, packets, bytes); |
| 45 | this.liveType = FlowLiveType.IMMEDIATE_FLOW; |
| 46 | } |
| 47 | |
Madan Jampani | c27b6b2 | 2016-02-05 11:36:31 -0800 | [diff] [blame] | 48 | /** |
| 49 | * Creates a typed flow entry from flow rule and its statistics, with default flow live type(IMMEDIATE_FLOW). |
| 50 | * |
| 51 | * @param rule the flow rule |
| 52 | * @param state the flow state |
| 53 | * @param life the flow duration since creation |
| 54 | * @param packets the flow packets count |
| 55 | * @param bytes the flow bytes count |
| 56 | * |
| 57 | */ |
| 58 | public DefaultTypedFlowEntry(FlowRule rule, FlowEntryState state, |
| 59 | long life, long packets, long bytes) { |
| 60 | super(rule, state, life, packets, bytes); |
| 61 | this.liveType = FlowLiveType.IMMEDIATE_FLOW; |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Creates a typed flow entry from flow rule, with default flow live type(IMMEDIATE_FLOW). |
| 66 | * |
| 67 | * @param rule the flow rule |
| 68 | * |
| 69 | */ |
| 70 | public DefaultTypedFlowEntry(FlowRule rule) { |
| 71 | super(rule); |
| 72 | this.liveType = FlowLiveType.IMMEDIATE_FLOW; |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * Creates a typed flow entry from flow entry, with default flow live type(IMMEDIATE_FLOW). |
| 77 | * |
| 78 | * @param fe the flow entry |
| 79 | * |
| 80 | */ |
| 81 | public DefaultTypedFlowEntry(FlowEntry fe) { |
Thiago Santos | 877914d | 2016-07-20 18:29:29 -0300 | [diff] [blame] | 82 | super(fe, fe.state(), fe.life(NANOSECONDS), NANOSECONDS, fe.packets(), fe.bytes()); |
Madan Jampani | c27b6b2 | 2016-02-05 11:36:31 -0800 | [diff] [blame] | 83 | this.liveType = FlowLiveType.IMMEDIATE_FLOW; |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * Creates a typed flow entry from flow rule and flow live type. |
| 88 | * |
| 89 | * @param rule the flow rule |
| 90 | * @param liveType the flow live type |
| 91 | * |
| 92 | */ |
| 93 | public DefaultTypedFlowEntry(FlowRule rule, FlowLiveType liveType) { |
| 94 | super(rule); |
| 95 | this.liveType = liveType; |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * Creates a typed flow entry from flow entry and flow live type. |
| 100 | * |
| 101 | * @param fe the flow rule |
| 102 | * @param liveType the flow live type |
| 103 | * |
| 104 | */ |
| 105 | public DefaultTypedFlowEntry(FlowEntry fe, FlowLiveType liveType) { |
Thiago Santos | 877914d | 2016-07-20 18:29:29 -0300 | [diff] [blame] | 106 | super(fe, fe.state(), fe.life(NANOSECONDS), NANOSECONDS, fe.packets(), fe.bytes()); |
Madan Jampani | c27b6b2 | 2016-02-05 11:36:31 -0800 | [diff] [blame] | 107 | this.liveType = liveType; |
| 108 | } |
| 109 | |
| 110 | /** |
| 111 | * Creates a typed flow entry from flow rule, error code and flow live type. |
| 112 | * |
| 113 | * @param rule the flow rule |
| 114 | * @param errType the flow error type |
| 115 | * @param errCode the flow error code |
| 116 | * @param liveType the flow live type |
| 117 | * |
| 118 | */ |
| 119 | public DefaultTypedFlowEntry(FlowRule rule, int errType, int errCode, FlowLiveType liveType) { |
| 120 | super(rule, errType, errCode); |
| 121 | this.liveType = liveType; |
| 122 | } |
| 123 | |
| 124 | @Override |
| 125 | public FlowLiveType flowLiveType() { |
| 126 | return this.liveType; |
| 127 | } |
| 128 | |
| 129 | @Override |
| 130 | public void setFlowLiveType(FlowLiveType liveType) { |
| 131 | this.liveType = liveType; |
| 132 | } |
| 133 | |
| 134 | @Override |
| 135 | public String toString() { |
| 136 | return toStringHelper(this) |
| 137 | .add("entry", super.toString()) |
| 138 | .add("type", liveType) |
| 139 | .toString(); |
| 140 | } |
| 141 | } |
| 142 | |