ssyoon90 | a98825a | 2015-08-26 00:48:15 +0900 | [diff] [blame] | 1 | /*
|
| 2 | * Copyright 2015 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 | */
|
| 16 |
|
| 17 | package org.onosproject.net.statistic;
|
| 18 |
|
| 19 | import org.onosproject.net.ConnectPoint;
|
| 20 | import org.onosproject.net.flow.FlowEntry;
|
| 21 | import org.onosproject.net.flow.TypedStoredFlowEntry;
|
| 22 | import org.onosproject.net.flow.DefaultTypedFlowEntry;
|
| 23 |
|
| 24 | import static com.google.common.base.Preconditions.checkNotNull;
|
| 25 |
|
| 26 | /**
|
| 27 | * Load of flow entry of flow live type.
|
| 28 | */
|
| 29 | public class TypedFlowEntryWithLoad {
|
| 30 | private ConnectPoint cp;
|
| 31 | private TypedStoredFlowEntry tfe;
|
| 32 | private Load load;
|
| 33 |
|
| 34 | //TODO: make this variables class, and share with NewAdaptivceFlowStatsCollector class
|
| 35 | private static final int CAL_AND_POLL_INTERVAL = 5; // means SHORT_POLL_INTERVAL
|
| 36 | private static final int MID_POLL_INTERVAL = 10;
|
| 37 | private static final int LONG_POLL_INTERVAL = 15;
|
| 38 |
|
Brian O'Connor | 5251562 | 2015-10-09 17:03:44 -0700 | [diff] [blame] | 39 | /**
|
| 40 | * Creates a new typed flow entry with load.
|
| 41 | *
|
| 42 | * @param cp connect point
|
| 43 | * @param tfe typed flow entry
|
| 44 | * @param load load
|
| 45 | */
|
ssyoon90 | a98825a | 2015-08-26 00:48:15 +0900 | [diff] [blame] | 46 | public TypedFlowEntryWithLoad(ConnectPoint cp, TypedStoredFlowEntry tfe, Load load) {
|
| 47 | this.cp = cp;
|
| 48 | this.tfe = tfe;
|
| 49 | this.load = load;
|
| 50 | }
|
| 51 |
|
Brian O'Connor | 5251562 | 2015-10-09 17:03:44 -0700 | [diff] [blame] | 52 | /**
|
| 53 | * Creates a new typed flow entry with load.
|
| 54 | *
|
| 55 | * @param cp connect point
|
| 56 | * @param tfe typed flow entry
|
| 57 | */
|
ssyoon90 | a98825a | 2015-08-26 00:48:15 +0900 | [diff] [blame] | 58 | public TypedFlowEntryWithLoad(ConnectPoint cp, TypedStoredFlowEntry tfe) {
|
| 59 | this.cp = cp;
|
| 60 | this.tfe = tfe;
|
| 61 | this.load = new DefaultLoad(tfe.bytes(), 0, typedPollInterval(tfe));
|
| 62 | }
|
| 63 |
|
Brian O'Connor | 5251562 | 2015-10-09 17:03:44 -0700 | [diff] [blame] | 64 | /**
|
| 65 | * Creates a new typed flow entry with load.
|
| 66 | *
|
| 67 | * @param cp connect point
|
| 68 | * @param fe flow entry
|
| 69 | */
|
ssyoon90 | a98825a | 2015-08-26 00:48:15 +0900 | [diff] [blame] | 70 | public TypedFlowEntryWithLoad(ConnectPoint cp, FlowEntry fe) {
|
| 71 | this.cp = cp;
|
| 72 | this.tfe = newTypedStoredFlowEntry(fe);
|
| 73 | this.load = new DefaultLoad(fe.bytes(), 0, typedPollInterval(this.tfe));
|
| 74 | }
|
| 75 |
|
| 76 | public ConnectPoint connectPoint() {
|
| 77 | return cp;
|
| 78 | }
|
| 79 | public TypedStoredFlowEntry typedStoredFlowEntry() {
|
| 80 | return tfe;
|
| 81 | }
|
| 82 | public Load load() {
|
| 83 | return load;
|
| 84 | }
|
| 85 | public void setLoad(Load load) {
|
| 86 | this.load = load;
|
| 87 | }
|
| 88 |
|
| 89 | /**
|
| 90 | * Returns short polling interval.
|
Brian O'Connor | 5251562 | 2015-10-09 17:03:44 -0700 | [diff] [blame] | 91 | *
|
| 92 | * @return short poll interval
|
ssyoon90 | a98825a | 2015-08-26 00:48:15 +0900 | [diff] [blame] | 93 | */
|
| 94 | public static int shortPollInterval() {
|
| 95 | return CAL_AND_POLL_INTERVAL;
|
| 96 | }
|
| 97 |
|
| 98 | /**
|
| 99 | * Returns mid polling interval.
|
Brian O'Connor | 5251562 | 2015-10-09 17:03:44 -0700 | [diff] [blame] | 100 | *
|
| 101 | * @return mid poll interval
|
ssyoon90 | a98825a | 2015-08-26 00:48:15 +0900 | [diff] [blame] | 102 | */
|
| 103 | public static int midPollInterval() {
|
| 104 | return MID_POLL_INTERVAL;
|
| 105 | }
|
| 106 |
|
| 107 | /**
|
| 108 | * Returns long polling interval.
|
Brian O'Connor | 5251562 | 2015-10-09 17:03:44 -0700 | [diff] [blame] | 109 | *
|
| 110 | * @return long poll interval
|
ssyoon90 | a98825a | 2015-08-26 00:48:15 +0900 | [diff] [blame] | 111 | */
|
| 112 | public static int longPollInterval() {
|
| 113 | return LONG_POLL_INTERVAL;
|
| 114 | }
|
| 115 |
|
| 116 | /**
|
| 117 | * Returns average polling interval.
|
Brian O'Connor | 5251562 | 2015-10-09 17:03:44 -0700 | [diff] [blame] | 118 | *
|
| 119 | * @return average poll interval
|
ssyoon90 | a98825a | 2015-08-26 00:48:15 +0900 | [diff] [blame] | 120 | */
|
| 121 | public static int avgPollInterval() {
|
| 122 | return (CAL_AND_POLL_INTERVAL + MID_POLL_INTERVAL + LONG_POLL_INTERVAL) / 3;
|
| 123 | }
|
| 124 |
|
| 125 | /**
|
| 126 | * Returns current typed flow entry's polling interval.
|
| 127 | *
|
| 128 | * @param tfe typed flow entry
|
Brian O'Connor | 5251562 | 2015-10-09 17:03:44 -0700 | [diff] [blame] | 129 | * @return typed poll interval
|
ssyoon90 | a98825a | 2015-08-26 00:48:15 +0900 | [diff] [blame] | 130 | */
|
| 131 | public static long typedPollInterval(TypedStoredFlowEntry tfe) {
|
| 132 | checkNotNull(tfe, "TypedStoredFlowEntry cannot be null");
|
| 133 |
|
| 134 | switch (tfe.flowLiveType()) {
|
| 135 | case LONG_FLOW:
|
| 136 | return LONG_POLL_INTERVAL;
|
| 137 | case MID_FLOW:
|
| 138 | return MID_POLL_INTERVAL;
|
| 139 | case SHORT_FLOW:
|
| 140 | case IMMEDIATE_FLOW:
|
| 141 | default:
|
| 142 | return CAL_AND_POLL_INTERVAL;
|
| 143 | }
|
| 144 | }
|
| 145 |
|
| 146 | /**
|
| 147 | * Creates a new typed flow entry with the given flow entry fe.
|
| 148 | *
|
| 149 | * @param fe flow entry
|
Brian O'Connor | 5251562 | 2015-10-09 17:03:44 -0700 | [diff] [blame] | 150 | * @return new typed flow entry
|
ssyoon90 | a98825a | 2015-08-26 00:48:15 +0900 | [diff] [blame] | 151 | */
|
| 152 | public static TypedStoredFlowEntry newTypedStoredFlowEntry(FlowEntry fe) {
|
| 153 | if (fe == null) {
|
| 154 | return null;
|
| 155 | }
|
| 156 |
|
| 157 | long life = fe.life();
|
| 158 |
|
| 159 | if (life >= LONG_POLL_INTERVAL) {
|
| 160 | return new DefaultTypedFlowEntry(fe, TypedStoredFlowEntry.FlowLiveType.LONG_FLOW);
|
| 161 | } else if (life >= MID_POLL_INTERVAL) {
|
| 162 | return new DefaultTypedFlowEntry(fe, TypedStoredFlowEntry.FlowLiveType.MID_FLOW);
|
| 163 | } else if (life >= CAL_AND_POLL_INTERVAL) {
|
| 164 | return new DefaultTypedFlowEntry(fe, TypedStoredFlowEntry.FlowLiveType.SHORT_FLOW);
|
| 165 | } else if (life >= 0) {
|
| 166 | return new DefaultTypedFlowEntry(fe, TypedStoredFlowEntry.FlowLiveType.IMMEDIATE_FLOW);
|
| 167 | } else { // life < 0
|
| 168 | return new DefaultTypedFlowEntry(fe, TypedStoredFlowEntry.FlowLiveType.UNKNOWN_FLOW);
|
| 169 | }
|
| 170 | }
|
| 171 | }
|