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
9 package org.opendaylight.openflowplugin.applications.frsync.util;
11 import java.util.Collections;
12 import java.util.HashMap;
13 import java.util.List;
15 import javax.annotation.Nonnull;
16 import javax.annotation.Nullable;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
27 * Helpers for flow lookups in {@link FlowCapableNode}.
29 public final class FlowCapableNodeLookups {
31 private static final Logger LOG = LoggerFactory.getLogger(FlowCapableNodeLookups.class);
33 private FlowCapableNodeLookups() {
34 throw new IllegalAccessError("non instantiable util class");
38 public static Map<Short, Table> wrapTablesToMap(@Nullable final List<Table> tables) {
39 final Map<Short, 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<SwitchFlowId, Flow> wrapFlowsToMap(@Nullable final List<Flow> flows) {
56 final Map<SwitchFlowId, 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 SwitchFlowId(flow), flow);
71 public static Flow flowMapLookupExisting(Flow flow, Map<SwitchFlowId, Flow> flowConfigMap) {
72 return flowConfigMap.get(new SwitchFlowId(flow));
76 public static Map<MeterId, Meter> wrapMetersToMap(@Nullable final List<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<Long, Group> wrapGroupsToMap(@Nullable final List<Group> groups) {
94 final Map<Long, 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);