Claudine Chiu | cdc4b8c | 2017-03-30 00:34:39 -0400 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2017-present Open Networking Foundation |
Claudine Chiu | cdc4b8c | 2017-03-30 00:34:39 -0400 | [diff] [blame] | 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.incubator.store.virtual.impl; |
| 18 | |
| 19 | import com.google.common.collect.Maps; |
Claudine Chiu | cdc4b8c | 2017-03-30 00:34:39 -0400 | [diff] [blame] | 20 | import org.onlab.util.KryoNamespace; |
| 21 | import org.onosproject.incubator.net.virtual.NetworkId; |
| 22 | import org.onosproject.incubator.net.virtual.VirtualNetworkFlowObjectiveStore; |
| 23 | import org.onosproject.store.serializers.KryoNamespaces; |
| 24 | import org.onosproject.store.service.ConsistentMap; |
| 25 | import org.onosproject.store.service.Serializer; |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 26 | import org.osgi.service.component.annotations.Component; |
Claudine Chiu | cdc4b8c | 2017-03-30 00:34:39 -0400 | [diff] [blame] | 27 | import org.slf4j.Logger; |
| 28 | |
| 29 | import java.util.concurrent.ConcurrentMap; |
| 30 | |
| 31 | import static org.slf4j.LoggerFactory.getLogger; |
| 32 | |
| 33 | /** |
| 34 | * Distributed flow objective store for virtual network. |
| 35 | */ |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 36 | @Component(immediate = true, enabled = false, service = VirtualNetworkFlowObjectiveStore.class) |
Claudine Chiu | cdc4b8c | 2017-03-30 00:34:39 -0400 | [diff] [blame] | 37 | public 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 | } |