blob: 5ae850975e495e322adee90229962b82ff4d896b [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;
20import org.apache.felix.scr.annotations.Component;
21import org.apache.felix.scr.annotations.Service;
22import org.onlab.util.KryoNamespace;
23import org.onosproject.incubator.net.virtual.NetworkId;
24import org.onosproject.incubator.net.virtual.VirtualNetworkFlowObjectiveStore;
25import org.onosproject.store.serializers.KryoNamespaces;
26import org.onosproject.store.service.ConsistentMap;
27import org.onosproject.store.service.Serializer;
28import org.slf4j.Logger;
29
30import java.util.concurrent.ConcurrentMap;
31
32import static org.slf4j.LoggerFactory.getLogger;
33
34/**
35 * Distributed flow objective store for virtual network.
36 */
37@Component(immediate = true, enabled = false)
38@Service
39public class DistributedVirtualFlowObjectiveStore
40 extends SimpleVirtualFlowObjectiveStore
41 implements VirtualNetworkFlowObjectiveStore {
42
43 private final Logger log = getLogger(getClass());
44
45 private ConsistentMap<NetworkId, ConcurrentMap<Integer, byte[]>> nextGroupsMap;
46 private static final String VNET_FLOW_OBJ_GROUP_MAP_NAME =
47 "onos-networkId-flowobjective-groups";
48 private static final String VNET_FLOW_OBJ_GROUP_MAP_FRIENDLYNAME =
49 "DistributedVirtualFlowObjectiveStore";
50
51 @Override
52 protected void initNextGroupsMap() {
53 nextGroupsMap = storageService.<NetworkId, ConcurrentMap<Integer, byte[]>>consistentMapBuilder()
54 .withName(VNET_FLOW_OBJ_GROUP_MAP_NAME)
55 .withSerializer(Serializer.using(
56 new KryoNamespace.Builder()
57 .register(KryoNamespaces.API)
58 .register(NetworkId.class)
59 .build(VNET_FLOW_OBJ_GROUP_MAP_FRIENDLYNAME)))
60 .build();
61
62 }
63
64 @Override
65 protected ConcurrentMap<Integer, byte[]> getNextGroups(NetworkId networkId) {
66 nextGroupsMap.computeIfAbsent(networkId, n -> {
67 log.debug("getNextGroups - creating new ConcurrentMap");
68 return Maps.newConcurrentMap();
69 });
70
71 return nextGroupsMap.get(networkId).value();
72 }
73
74 @Override
75 protected void updateNextGroupsMap(NetworkId networkId, ConcurrentMap<Integer,
76 byte[]> nextGroups) {
77 nextGroupsMap.put(networkId, nextGroups);
78 }
79
80}