blob: 6e8cb7b408f47f1ba33334aa3aa6828b3cc1120d [file] [log] [blame]
Claudine Chiucdc4b8c2017-03-30 00:34:39 -04001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2017-present Open Networking Foundation
Claudine Chiucdc4b8c2017-03-30 00:34:39 -04003 *
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.incubator.store.virtual.impl;
18
19import com.google.common.collect.Maps;
Claudine Chiucdc4b8c2017-03-30 00:34:39 -040020import org.onlab.util.KryoNamespace;
21import org.onosproject.incubator.net.virtual.NetworkId;
22import org.onosproject.incubator.net.virtual.VirtualNetworkFlowObjectiveStore;
23import org.onosproject.store.serializers.KryoNamespaces;
24import org.onosproject.store.service.ConsistentMap;
25import org.onosproject.store.service.Serializer;
Ray Milkeyd84f89b2018-08-17 14:54:17 -070026import org.osgi.service.component.annotations.Component;
Claudine Chiucdc4b8c2017-03-30 00:34:39 -040027import org.slf4j.Logger;
28
29import java.util.concurrent.ConcurrentMap;
30
31import static org.slf4j.LoggerFactory.getLogger;
32
33/**
34 * Distributed flow objective store for virtual network.
35 */
Ray Milkeyd84f89b2018-08-17 14:54:17 -070036@Component(immediate = true, enabled = false, service = VirtualNetworkFlowObjectiveStore.class)
Claudine Chiucdc4b8c2017-03-30 00:34:39 -040037public class DistributedVirtualFlowObjectiveStore
38 extends SimpleVirtualFlowObjectiveStore
39 implements VirtualNetworkFlowObjectiveStore {
40
41 private final Logger log = getLogger(getClass());
42
43 private ConsistentMap<NetworkId, ConcurrentMap<Integer, byte[]>> nextGroupsMap;
44 private static final String VNET_FLOW_OBJ_GROUP_MAP_NAME =
45 "onos-networkId-flowobjective-groups";
46 private static final String VNET_FLOW_OBJ_GROUP_MAP_FRIENDLYNAME =
47 "DistributedVirtualFlowObjectiveStore";
48
49 @Override
50 protected void initNextGroupsMap() {
51 nextGroupsMap = storageService.<NetworkId, ConcurrentMap<Integer, byte[]>>consistentMapBuilder()
52 .withName(VNET_FLOW_OBJ_GROUP_MAP_NAME)
53 .withSerializer(Serializer.using(
54 new KryoNamespace.Builder()
55 .register(KryoNamespaces.API)
56 .register(NetworkId.class)
57 .build(VNET_FLOW_OBJ_GROUP_MAP_FRIENDLYNAME)))
58 .build();
59
60 }
61
62 @Override
63 protected ConcurrentMap<Integer, byte[]> getNextGroups(NetworkId networkId) {
64 nextGroupsMap.computeIfAbsent(networkId, n -> {
65 log.debug("getNextGroups - creating new ConcurrentMap");
66 return Maps.newConcurrentMap();
67 });
68
69 return nextGroupsMap.get(networkId).value();
70 }
71
72 @Override
73 protected void updateNextGroupsMap(NetworkId networkId, ConcurrentMap<Integer,
74 byte[]> nextGroups) {
75 nextGroupsMap.put(networkId, nextGroups);
76 }
77
78}