2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.controller.frm;
11 import java.math.BigInteger;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
14 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
16 import com.google.common.base.Preconditions;
17 import com.google.common.util.concurrent.AtomicLongMap;
20 * forwardingrules-manager
21 * org.opendaylight.controller.frm
23 * Singleton FlowCookieProducer contains a FlowCookie generator which is generated unique
24 * flowCookie identifier for every flow in same Table. That could help with quick
25 * identification of flow statistic because DataStore/CONFIGURATION could contains
26 * a lot of flows with same flowCookie. So we are replacing original flowCookie
27 * with unique and we are building final FlowCookieMap in DataStore/OPERATIONAL
29 * @author <a href="mailto:vdemcak@cisco.com">Vaclav Demcak</a>
31 * Created: Jun 13, 2014
33 public enum FlowCookieProducer {
37 /* Flow_Cookie_Key and Flow_Ids MapHolder */
38 private static final AtomicLongMap<InstanceIdentifier<Table>> cookieKeys = AtomicLongMap.create();
41 * Method returns the unique cookie for a node table.
42 * Flow Cookie Key signs List<FlowId> for a right flow statistic identification
43 * in the DataStore/operational.
44 * We need a List<FlowId> because system doesn't guarantee unique mapping
45 * from flow_cookie to flow_id. REST Operations doesn't used FRM yet, so
46 * cookie from user input could have a user input flow ID and an alien system ID
47 * which is generated by system.
49 * @param InstanceIdentifier<Table> tableIdentifier
50 * @return unique BigInteger flowCookie for a node table
52 public BigInteger getNewCookie(final InstanceIdentifier<Table> tableIdentifier) {
53 FlowCookieProducer.validationTableIdentifier(tableIdentifier);
54 if ( cookieKeys.containsKey(tableIdentifier)) {
55 /* new identifier always starts from ONE because
56 * ZERO is reserved for the NO_COOKIES flows */
57 return BigInteger.valueOf(cookieKeys.addAndGet(tableIdentifier, 1L));
59 return BigInteger.valueOf(cookieKeys.incrementAndGet(tableIdentifier));
64 * Method cleans the node table flow_cookie_key for the disconnected Node.
66 * @param InstanceIdentifier<Table> tableIdentifier
68 public void clean(final InstanceIdentifier<Table> tableIdentifier) {
69 FlowCookieProducer.validationTableIdentifier(tableIdentifier);
70 cookieKeys.remove(tableIdentifier);
74 * Help the TableIdentifer input validation method
76 private static void validationTableIdentifier(final InstanceIdentifier<Table> tableIdent) {
77 Preconditions.checkArgument(tableIdent != null, "Input validation exception: TableIdentifier can not be null !");