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 | |
| 19 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 20 | |
| 21 | /** |
| 22 | * Default flow entry class with FlowLiveType value, IMMEDIATE_FLOW, SHORT_FLOW, MID_FLOW, LONG_FLOW. |
| 23 | */ |
| 24 | public class DefaultTypedFlowEntry extends DefaultFlowEntry |
| 25 | implements TypedStoredFlowEntry { |
| 26 | private FlowLiveType liveType; |
| 27 | |
| 28 | /** |
| 29 | * Creates a typed flow entry from flow rule and its statistics, with default flow live type(IMMEDIATE_FLOW). |
| 30 | * |
| 31 | * @param rule the flow rule |
| 32 | * @param state the flow state |
| 33 | * @param life the flow duration since creation |
| 34 | * @param packets the flow packets count |
| 35 | * @param bytes the flow bytes count |
| 36 | * |
| 37 | */ |
| 38 | public DefaultTypedFlowEntry(FlowRule rule, FlowEntryState state, |
| 39 | long life, long packets, long bytes) { |
| 40 | super(rule, state, life, packets, bytes); |
| 41 | this.liveType = FlowLiveType.IMMEDIATE_FLOW; |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Creates a typed flow entry from flow rule, with default flow live type(IMMEDIATE_FLOW). |
| 46 | * |
| 47 | * @param rule the flow rule |
| 48 | * |
| 49 | */ |
| 50 | public DefaultTypedFlowEntry(FlowRule rule) { |
| 51 | super(rule); |
| 52 | this.liveType = FlowLiveType.IMMEDIATE_FLOW; |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Creates a typed flow entry from flow entry, with default flow live type(IMMEDIATE_FLOW). |
| 57 | * |
| 58 | * @param fe the flow entry |
| 59 | * |
| 60 | */ |
| 61 | public DefaultTypedFlowEntry(FlowEntry fe) { |
| 62 | super(fe, fe.state(), fe.life(), fe.packets(), fe.bytes()); |
| 63 | this.liveType = FlowLiveType.IMMEDIATE_FLOW; |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Creates a typed flow entry from flow rule and flow live type. |
| 68 | * |
| 69 | * @param rule the flow rule |
| 70 | * @param liveType the flow live type |
| 71 | * |
| 72 | */ |
| 73 | public DefaultTypedFlowEntry(FlowRule rule, FlowLiveType liveType) { |
| 74 | super(rule); |
| 75 | this.liveType = liveType; |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Creates a typed flow entry from flow entry and flow live type. |
| 80 | * |
| 81 | * @param fe the flow rule |
| 82 | * @param liveType the flow live type |
| 83 | * |
| 84 | */ |
| 85 | public DefaultTypedFlowEntry(FlowEntry fe, FlowLiveType liveType) { |
| 86 | super(fe, fe.state(), fe.life(), fe.packets(), fe.bytes()); |
| 87 | this.liveType = liveType; |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * Creates a typed flow entry from flow rule, error code and flow live type. |
| 92 | * |
| 93 | * @param rule the flow rule |
| 94 | * @param errType the flow error type |
| 95 | * @param errCode the flow error code |
| 96 | * @param liveType the flow live type |
| 97 | * |
| 98 | */ |
| 99 | public DefaultTypedFlowEntry(FlowRule rule, int errType, int errCode, FlowLiveType liveType) { |
| 100 | super(rule, errType, errCode); |
| 101 | this.liveType = liveType; |
| 102 | } |
| 103 | |
| 104 | @Override |
| 105 | public FlowLiveType flowLiveType() { |
| 106 | return this.liveType; |
| 107 | } |
| 108 | |
| 109 | @Override |
| 110 | public void setFlowLiveType(FlowLiveType liveType) { |
| 111 | this.liveType = liveType; |
| 112 | } |
| 113 | |
| 114 | @Override |
| 115 | public String toString() { |
| 116 | return toStringHelper(this) |
| 117 | .add("entry", super.toString()) |
| 118 | .add("type", liveType) |
| 119 | .toString(); |
| 120 | } |
| 121 | } |
| 122 | |