blob: 80b78542adb264a67b7de6d03397fdbc2e0796e0 [file] [log] [blame]
Madan Jampanic27b6b22016-02-05 11:36:31 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Madan Jampanic27b6b22016-02-05 11:36:31 -08003 *
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
17package org.onosproject.net.flow;
18
Thiago Santos877914d2016-07-20 18:29:29 -030019import java.util.concurrent.TimeUnit;
20
Madan Jampanic27b6b22016-02-05 11:36:31 -080021import static com.google.common.base.MoreObjects.toStringHelper;
Thiago Santos877914d2016-07-20 18:29:29 -030022import static java.util.concurrent.TimeUnit.NANOSECONDS;
Madan Jampanic27b6b22016-02-05 11:36:31 -080023
24/**
25 * Default flow entry class with FlowLiveType value, IMMEDIATE_FLOW, SHORT_FLOW, MID_FLOW, LONG_FLOW.
26 */
27public class DefaultTypedFlowEntry extends DefaultFlowEntry
28 implements TypedStoredFlowEntry {
Sangsik Yoonb1b823f2016-05-16 18:55:39 +090029 private TypedStoredFlowEntry.FlowLiveType liveType;
Madan Jampanic27b6b22016-02-05 11:36:31 -080030
Thiago Santos877914d2016-07-20 18:29:29 -030031
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);
Sangsik Yoonb1b823f2016-05-16 18:55:39 +090045 this.liveType = TypedStoredFlowEntry.FlowLiveType.IMMEDIATE_FLOW;
Thiago Santos877914d2016-07-20 18:29:29 -030046 }
47
Madan Jampanic27b6b22016-02-05 11:36:31 -080048 /**
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);
Sangsik Yoonb1b823f2016-05-16 18:55:39 +090061 this.liveType = TypedStoredFlowEntry.FlowLiveType.IMMEDIATE_FLOW;
Madan Jampanic27b6b22016-02-05 11:36:31 -080062 }
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);
Sangsik Yoonb1b823f2016-05-16 18:55:39 +090072 this.liveType = TypedStoredFlowEntry.FlowLiveType.IMMEDIATE_FLOW;
Madan Jampanic27b6b22016-02-05 11:36:31 -080073 }
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 Santos877914d2016-07-20 18:29:29 -030082 super(fe, fe.state(), fe.life(NANOSECONDS), NANOSECONDS, fe.packets(), fe.bytes());
Sangsik Yoonb1b823f2016-05-16 18:55:39 +090083 this.liveType = TypedStoredFlowEntry.FlowLiveType.IMMEDIATE_FLOW;
Madan Jampanic27b6b22016-02-05 11:36:31 -080084 }
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 */
Sangsik Yoonb1b823f2016-05-16 18:55:39 +090093 public DefaultTypedFlowEntry(FlowRule rule, TypedStoredFlowEntry.FlowLiveType liveType) {
Madan Jampanic27b6b22016-02-05 11:36:31 -080094 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 */
Sangsik Yoonb1b823f2016-05-16 18:55:39 +0900105 public DefaultTypedFlowEntry(FlowEntry fe, TypedStoredFlowEntry.FlowLiveType liveType) {
Thiago Santos877914d2016-07-20 18:29:29 -0300106 super(fe, fe.state(), fe.life(NANOSECONDS), NANOSECONDS, fe.packets(), fe.bytes());
Madan Jampanic27b6b22016-02-05 11:36:31 -0800107 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 */
Sangsik Yoonb1b823f2016-05-16 18:55:39 +0900119 public DefaultTypedFlowEntry(FlowRule rule, int errType, int errCode,
120 TypedStoredFlowEntry.FlowLiveType liveType) {
Madan Jampanic27b6b22016-02-05 11:36:31 -0800121 super(rule, errType, errCode);
122 this.liveType = liveType;
123 }
124
125 @Override
Sangsik Yoonb1b823f2016-05-16 18:55:39 +0900126 public TypedStoredFlowEntry.FlowLiveType flowLiveType() {
Madan Jampanic27b6b22016-02-05 11:36:31 -0800127 return this.liveType;
128 }
129
130 @Override
Sangsik Yoonb1b823f2016-05-16 18:55:39 +0900131 public void setFlowLiveType(TypedStoredFlowEntry.FlowLiveType liveType) {
Madan Jampanic27b6b22016-02-05 11:36:31 -0800132 this.liveType = liveType;
133 }
134
135 @Override
136 public String toString() {
137 return toStringHelper(this)
138 .add("entry", super.toString())
139 .add("type", liveType)
140 .toString();
141 }
142}
143