d3d62e35c7b0cfb078f7def90734953a092f2013
[hc2vpp.git] /
1 /*
2  * Copyright (c) 2019 PANTHEON.tech.
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 io.fd.hc2vpp.v3po.interfacesstate.cache;
18
19 import io.fd.vpp.jvpp.core.dto.VnetPerInterfaceCombinedCounters;
20 import java.time.LocalDateTime;
21 import java.util.HashMap;
22 import javax.annotation.Nullable;
23
24 public class InterfaceCacheStatisticsDumpManagerImpl implements InterfaceCacheStatisticsDumpManager {
25
26     private final HashMap<Integer, InterfaceCacheStatisticsSample> statistics;
27
28     public InterfaceCacheStatisticsDumpManagerImpl() {
29         statistics = new HashMap<>();
30     }
31
32     @Nullable
33     @Override
34     public InterfaceCacheStatisticsSample getStatisticsData(final int ifcSwIndex) {
35         return statistics.getOrDefault(ifcSwIndex, null);
36     }
37
38     @Override
39     public void setStatisticsData(final VnetPerInterfaceCombinedCounters data, LocalDateTime captureTime,
40                                   final int ifcSwIndex) {
41         statistics.put(ifcSwIndex, new InterfaceCacheStatisticsSample(data, captureTime));
42     }
43
44     @Nullable
45     @Override
46     public int[] getEnabledInterfaces() {
47         return statistics.keySet().stream().mapToInt(i -> i).toArray();
48     }
49
50     @Override
51     public void disableInterface(final int ifcSwIndex) {
52         statistics.remove(ifcSwIndex);
53     }
54
55     @Override
56     public void disableAll() {
57         statistics.clear();
58     }
59
60     @Override
61     public void enableInterface(final int index) {
62         statistics.put(index,
63                 new InterfaceCacheStatisticsSample(new VnetPerInterfaceCombinedCounters(), LocalDateTime.now()));
64     }
65 }