Claudine Chiu | cdc4b8c | 2017-03-30 00:34:39 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017-present 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 | |
| 17 | package org.onosproject.incubator.store.virtual.impl; |
| 18 | |
| 19 | import com.google.common.collect.Maps; |
| 20 | import org.apache.felix.scr.annotations.Component; |
| 21 | import org.apache.felix.scr.annotations.Service; |
| 22 | import org.onlab.util.KryoNamespace; |
| 23 | import org.onosproject.incubator.net.virtual.NetworkId; |
| 24 | import org.onosproject.incubator.net.virtual.VirtualNetworkFlowObjectiveStore; |
| 25 | import org.onosproject.store.serializers.KryoNamespaces; |
| 26 | import org.onosproject.store.service.ConsistentMap; |
| 27 | import org.onosproject.store.service.Serializer; |
| 28 | import org.slf4j.Logger; |
| 29 | |
| 30 | import java.util.concurrent.ConcurrentMap; |
| 31 | |
| 32 | import static org.slf4j.LoggerFactory.getLogger; |
| 33 | |
| 34 | /** |
| 35 | * Distributed flow objective store for virtual network. |
| 36 | */ |
| 37 | @Component(immediate = true, enabled = false) |
| 38 | @Service |
| 39 | public 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 | } |