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.mappers;
12 import com.google.common.base.Preconditions;
13 import org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.flat.overlay.RoutingInfo;
15 import java.util.HashMap;
18 * Created by Shakib Ahmed on 5/4/17.
20 public class HostVrfRoutingInformationMapper {
21 HashMap<String, HashMap<Long, RoutingInfo> > mapper;
23 private static final HostVrfRoutingInformationMapper INSTANCE = new HostVrfRoutingInformationMapper();
25 private HostVrfRoutingInformationMapper() {
26 mapper = new HashMap<>();
29 public static HostVrfRoutingInformationMapper getInstance() {
33 public void addRoutingVrfToHost(String hostId, long vrf, RoutingInfo routingInfo) {
34 HashMap<Long, RoutingInfo> routingInfoMapper = mapper.get(hostId);
36 if (routingInfoMapper == null) {
37 routingInfoMapper = new HashMap<>();
38 mapper.put(hostId, routingInfoMapper);
41 routingInfoMapper.put(vrf, routingInfo);
44 public boolean vrfExists(String hostId, long vrf) {
45 return mapper.containsKey(hostId) && mapper.get(hostId).containsKey(vrf);
48 public String getProtocolName(String hostId, long vrf) {
49 Preconditions.checkArgument(vrfExists(hostId, vrf));
51 return mapper.get(hostId).get(vrf).getProtocolName();
54 public void addStaticRoute(String hostId, long vrf) {
55 HashMap<Long, RoutingInfo> routingInfoMapper = mapper.get(hostId);
57 Preconditions.checkNotNull(routingInfoMapper, "Routing protocol not created, can't add route entry");
59 RoutingInfo routingInfo = routingInfoMapper.get(vrf);
61 Preconditions.checkNotNull(routingInfoMapper, "VRF was not created for this host");
63 routingInfo.incrementCount();
66 public Long getEndPointCountInVrf(String hostId, long vrf) {
69 if (vrfExists(hostId, vrf)) {
70 count = mapper.get(hostId).get(vrf).getCount();
72 return (long) (count + 1);