2 * Copyright (c) 2017 Cisco Systems. 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.groupbasedpolicy.renderer.vpp.lisp.info.container;
10 import com.google.common.base.Preconditions;
11 import com.google.common.collect.HashBasedTable;
12 import com.google.common.collect.Sets;
13 import com.google.common.collect.Table;
15 import java.util.HashMap;
18 import org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.info.container.states.PhysicalInterfaces;
19 import org.opendaylight.groupbasedpolicy.renderer.vpp.listener.VppEndpointListener;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
23 public class HostRelatedInfoContainer {
24 private HashMap<String, PhysicalInterfaces> hostNameToPhysicalInterfacesMapper;
26 //route IDs on an interface on a host
27 private Table<String, String, Set<Long>> routeIdsByHostByVrf = HashBasedTable.create();
29 private static final HostRelatedInfoContainer INSTANCE = new HostRelatedInfoContainer();
31 private HostRelatedInfoContainer() {
32 this.hostNameToPhysicalInterfacesMapper = new HashMap<>();
35 public void addRouteToIntfc(String hostname, String intfName, Long routeId) {
36 Preconditions.checkNotNull(hostname);
37 Preconditions.checkNotNull(intfName);
38 Preconditions.checkNotNull(routeId);
39 if (routeIdsByHostByVrf.get(hostname, intfName) != null) {
40 routeIdsByHostByVrf.get(hostname, intfName).add(routeId);
43 routeIdsByHostByVrf.put(hostname, intfName, Sets.newHashSet(routeId));
46 public void deleteRouteFromIntfc(String hostname, String intfName, Long routeId) {
47 Preconditions.checkNotNull(hostname);
48 Preconditions.checkNotNull(intfName);
49 Preconditions.checkNotNull(routeId);
50 if (routeIdsByHostByVrf.get(hostname, intfName) != null) {
51 routeIdsByHostByVrf.get(hostname, intfName).remove(routeId);
55 private static final Logger LOG = LoggerFactory.getLogger(VppEndpointListener.class);
57 public boolean intfcIsBusy(String hostname, String intfName) {
58 Preconditions.checkNotNull(hostname);
59 Preconditions.checkNotNull(intfName);
60 if (routeIdsByHostByVrf.get(hostname, intfName) != null) {
61 int size = routeIdsByHostByVrf.get(hostname, intfName).size();
62 LOG.trace("ISPORTBUSY -> hostname: {}, inftName: {}, entries: {}", hostname, intfName,
63 routeIdsByHostByVrf.get(hostname, intfName));
66 LOG.trace("ISPORTBUSY -> not busy interface on hostname: {}, inftName: {}", hostname, intfName);
70 public static HostRelatedInfoContainer getInstance() {
74 public PhysicalInterfaces getPhysicalInterfaceState(String hostName) {
75 return hostNameToPhysicalInterfacesMapper.get(hostName);
78 public void setPhysicalInterfaceStateOfHost(String hostName, PhysicalInterfaces physicalInterfaces) {
79 hostNameToPhysicalInterfacesMapper.put(hostName, physicalInterfaces);
82 public void removePhysicalInterfaceStateOfHost(String hostName) {
83 //TODO should be called when host is removed
84 hostNameToPhysicalInterfacesMapper.remove(hostName);