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
9 package org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.bvi;
11 import com.google.common.collect.ArrayListMultimap;
12 import com.google.common.collect.Multimap;
13 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
15 import java.util.HashMap;
16 import java.util.List;
17 import java.util.stream.Collectors;
20 * Created by Shakib Ahmed on 4/26/17.
22 public class BviHostSpecificInfo {
23 private HashMap<String, HashMap<String, String>> hostIdToSubnetMapper;
24 private Multimap<String, String> subnetUuidToHostIdList;
26 public BviHostSpecificInfo() {
27 hostIdToSubnetMapper = new HashMap<>();
28 subnetUuidToHostIdList = ArrayListMultimap.create();
31 private HashMap<String, String> getSubnetsOfHost(String hostName) {
32 return hostIdToSubnetMapper.get(hostName);
35 private void putSubnetInfoOfAHost(String hostId, String subnetUuid, String interfaceName) {
36 HashMap<String, String> subnetsOfAHost = getSubnetsOfHost(hostId);
38 if (subnetsOfAHost == null) {
39 subnetsOfAHost = new HashMap<>();
40 hostIdToSubnetMapper.put(hostId, subnetsOfAHost);
42 subnetsOfAHost.put(subnetUuid, interfaceName);
45 public boolean bviAlreadyExists(String hostName, String subnetUuid) {
46 return hostIdToSubnetMapper.containsKey(hostName) &&
47 hostIdToSubnetMapper.get(hostName).containsKey(subnetUuid);
50 public void addBviForHost(String hostName, String subnetUuid, String interfaceName) {
51 putSubnetInfoOfAHost(hostName, subnetUuid, interfaceName);
52 subnetUuidToHostIdList.put(subnetUuid, hostName);
55 public int getBviCount(String hostName) {
56 if (hostIdToSubnetMapper.get(hostName) == null) {
59 return hostIdToSubnetMapper.get(hostName).size();
62 public void clearSubnet(String subnetUuid) {
63 subnetUuidToHostIdList.get(subnetUuid).forEach(hostId -> {
64 deleteParticularSubnetFromHost(hostId, subnetUuid);
66 subnetUuidToHostIdList.get(subnetUuid).clear();
69 private void deleteParticularSubnetFromHost(String hostId, String subnetUuid) {
70 hostIdToSubnetMapper.get(hostId).remove(subnetUuid);
73 public List<String> getHostsWithSubnet(String subnetUuid) {
74 return subnetUuidToHostIdList.get(subnetUuid).stream().collect(Collectors.toList());
77 public String getInterfaceNameForBviInHost(String hostId, String subnetUuid) {
78 if (hostIdToSubnetMapper.get(hostId) != null) {
79 return hostIdToSubnetMapper.get(hostId).get(subnetUuid);