7494c8140d55f4567e15a627f49d838885bc82d5
[onosfw.git] /
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 package org.onosproject.bgp.controller.impl;
17
18 import org.onosproject.bgp.controller.BgpPacketStats;
19
20 /**
21  * A representation of a packet context which allows any provider
22  * to view a packet in event, but may block the response to the
23  * event if blocked has been called. This packet context can be used
24  * to react to the packet in event with a packet out.
25  */
26 public class BgpPacketStatsImpl implements BgpPacketStats {
27
28     private int inPacketCount;
29     private int outPacketCount;
30     private int wrongPacketCount;
31     private long time;
32
33     /**
34      * Resets parameter.
35      */
36     public BgpPacketStatsImpl() {
37         this.inPacketCount = 0;
38         this.outPacketCount = 0;
39         this.wrongPacketCount = 0;
40         this.time = 0;
41     }
42
43     /**
44      * Get the outgoing packet count number.
45      *
46      * @return packet count
47      */
48     public int outPacketCount() {
49         return outPacketCount;
50     }
51
52     /**
53      * Get the incoming packet count number.
54      *
55      * @return packet count
56      */
57     public int inPacketCount() {
58         return inPacketCount;
59     }
60
61     /**
62      * Get the wrong packet count number.
63      *
64      * @return packet count
65      */
66     public int wrongPacketCount() {
67         return wrongPacketCount;
68     }
69
70     /**
71      * Increments the received packet counter.
72      */
73     public void addInPacket() {
74         this.inPacketCount++;
75     }
76
77     /**
78      * Increments the sent packet counter.
79      */
80     public void addOutPacket() {
81         this.outPacketCount++;
82     }
83
84     /**
85      * Increments the sent packet counter by specified value.
86      *
87      * @param value of no of packets sent
88      */
89     public void addOutPacket(int value) {
90         this.outPacketCount = this.outPacketCount + value;
91     }
92
93     /**
94      * Increments the wrong packet counter.
95      */
96     public void addWrongPacket() {
97         this.wrongPacketCount++;
98     }
99
100     /**
101      * Resets wrong packet count.
102      */
103     public void resetWrongPacket() {
104         this.wrongPacketCount = 0;
105     }
106
107     /**
108      * Get the time.
109      *
110      * @return time
111      */
112     public long getTime() {
113         return this.time;
114     }
115
116     /**
117      * Sets the time.
118      *
119      * @param time value to set
120      */
121     public void setTime(long time) {
122         this.time = time;
123     }
124 }