blob: a5e85b2a71bd9249d0183d26708842a5961cea40 [file] [log] [blame]
Sangsik Yoonb1b823f2016-05-16 18:55:39 +09001/*
2 * Copyright 2014-present Open Networking Laboratory
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 */
16package org.onosproject.net.statistic;
17
18import org.onosproject.net.ConnectPoint;
19import org.onosproject.net.flow.FlowEntry;
20import org.onosproject.net.flow.StoredFlowEntry;
21
22import static com.google.common.base.Preconditions.checkArgument;
23import static com.google.common.base.Preconditions.checkNotNull;
24
25/**
26 * Load of flow entry with flow live type.
27 */
28public class FlowEntryWithLoad {
29 private final ConnectPoint cp;
30 private final FlowEntry fe;
31 private final Load load;
32
33 /**
34 * Creates a new flow entry with load.
35 *
36 * @param cp connect point
37 * @param fe flow entry with live type
38 * @param load load
39 */
40 public FlowEntryWithLoad(ConnectPoint cp, FlowEntry fe, Load load) {
41 checkArgument(fe instanceof StoredFlowEntry, "FlowEntry must be StoredFlowEntry class type");
42 this.cp = cp;
43 this.fe = fe;
44 this.load = load;
45 }
46
47 /**
48 * Creates a new flow entry with load.
49 *
50 * @param cp connect point
51 * @param fe flow entry with live type
52 */
53 public FlowEntryWithLoad(ConnectPoint cp, FlowEntry fe) {
54 checkArgument(fe instanceof StoredFlowEntry, "FlowEntry must be StoredFlowEntry class type");
55 this.cp = cp;
56 this.fe = fe;
57 this.load = new DefaultLoad(fe.bytes(), 0, typedPollInterval(fe));
58 }
59
60 /**
61 * Returns connect point.
62 *
63 * @return connect point
64 */
65 public ConnectPoint connectPoint() {
66 return cp;
67 }
68
69 /**
70 * Returns stored flow entry.
71 *
72 * @return flow entry
73 */
74 public StoredFlowEntry storedFlowEntry() {
75 return (StoredFlowEntry) fe;
76 }
77
78 /**
79 * Returns current load.
80 *
81 * @return load
82 */
83 public Load load() {
84 return load;
85 }
86
87 /**
88 * Returns current flow entry's polling interval.
89 *
90 * @param fe flow entry
91 * @return poll interval time unit in seconds
92 */
93 private long typedPollInterval(FlowEntry fe) {
94 checkNotNull(fe, "FlowEntry cannot be null");
95
96 PollInterval pollIntervalInstance = PollInterval.getInstance();
97
98 switch (fe.liveType()) {
99 case LONG:
100 return pollIntervalInstance.getLongPollInterval();
101 case MID:
102 return pollIntervalInstance.getMidPollInterval();
103 case SHORT:
104 case IMMEDIATE:
105 case UNKNOWN:
106 default:
107 return pollIntervalInstance.getPollInterval();
108 }
109 }
110}