2 * Copyright (c) 2016 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
8 package org.opendaylight.openflowplugin.applications.frsync.util;
10 import java.util.Collection;
11 import java.util.Collections;
12 import java.util.HashMap;
14 import org.eclipse.jdt.annotation.NonNull;
15 import org.eclipse.jdt.annotation.Nullable;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId;
22 import org.opendaylight.yangtools.yang.common.Uint32;
23 import org.opendaylight.yangtools.yang.common.Uint8;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
28 * Helpers for flow lookups in {@link FlowCapableNode}.
30 public final class FlowCapableNodeLookups {
31 private static final Logger LOG = LoggerFactory.getLogger(FlowCapableNodeLookups.class);
33 private FlowCapableNodeLookups() {
38 public static Map<Uint8, Table> wrapTablesToMap(@Nullable final Collection<Table> tables) {
39 final Map<Uint8, Table> tableMap;
42 tableMap = Collections.emptyMap();
44 LOG.trace("tables found: {}", tables.size());
45 tableMap = new HashMap<>();
46 for (Table table : tables) {
47 tableMap.put(table.getId(), table);
55 public static Map<FlowDescriptor, Flow> wrapFlowsToMap(@Nullable final Collection<Flow> flows) {
56 final Map<FlowDescriptor, Flow> flowMap;
59 flowMap = Collections.emptyMap();
61 LOG.trace("flows found: {}", flows.size());
62 flowMap = new HashMap<>();
63 for (Flow flow : flows) {
64 flowMap.put(new FlowDescriptor(flow), flow);
71 public static Flow flowMapLookupExisting(Flow flow, Map<FlowDescriptor, Flow> flowConfigMap) {
72 return flowConfigMap.get(new FlowDescriptor(flow));
76 public static Map<MeterId, Meter> wrapMetersToMap(@Nullable final Collection<Meter> meters) {
77 final Map<MeterId, Meter> meterMap;
80 meterMap = Collections.emptyMap();
82 LOG.trace("meters found: {}", meters.size());
83 meterMap = new HashMap<>();
84 for (Meter meter : meters) {
85 meterMap.put(meter.getMeterId(), meter);
93 public static Map<Uint32, Group> wrapGroupsToMap(@Nullable final Collection<Group> groups) {
94 final Map<Uint32, Group> groupMap;
97 groupMap = Collections.emptyMap();
99 LOG.trace("groups found: {}", groups.size());
100 groupMap = new HashMap<>();
101 for (Group group : groups) {
102 groupMap.put(group.getGroupId().getValue(), group);