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;
14 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
16 import java.util.HashMap;
19 * Created by Shakib Ahmed on 5/4/17.
21 public class HostVrfRoutingInformationMapper {
22 HashMap<String, HashMap<Long, RoutingInfo> > mapper;
24 private static final HostVrfRoutingInformationMapper INSTANCE = new HostVrfRoutingInformationMapper();
26 private HostVrfRoutingInformationMapper() {
27 mapper = new HashMap<>();
30 public static HostVrfRoutingInformationMapper getInstance() {
34 public void addRoutingVrfToHost(String hostId, long vrf, RoutingInfo routingInfo) {
35 HashMap<Long, RoutingInfo> routingInfoMapper = mapper.get(hostId);
37 if (routingInfoMapper == null) {
38 routingInfoMapper = new HashMap<>();
39 mapper.put(hostId, routingInfoMapper);
42 routingInfoMapper.put(vrf, routingInfo);
45 public boolean vrfExists(String hostId, long vrf) {
46 return mapper.containsKey(hostId) && mapper.get(hostId).containsKey(vrf);
49 public String getProtocolName(String hostId, long vrf) {
50 Preconditions.checkArgument(vrfExists(hostId, vrf));
52 return mapper.get(hostId).get(vrf).getProtocolName();
55 public void addStaticRoute(String hostId, long vrf, Ipv4Address ip) {
56 HashMap<Long, RoutingInfo> routingInfoMapper = mapper.get(hostId);
58 Preconditions.checkNotNull(routingInfoMapper, "Routing protocol not created, can't add route entry");
60 RoutingInfo routingInfo = routingInfoMapper.get(vrf);
62 Preconditions.checkNotNull(routingInfoMapper, "VRF was not created for this host");
64 routingInfo.addIpInVrf(ip);
67 public Long getEndPointCountInVrf(String hostId, long vrf) {
70 if (vrfExists(hostId, vrf)) {
71 count = mapper.get(hostId).get(vrf).getCount();
73 return (long) (count + 1);
76 public boolean ipAlreadyExistsInHostVrf(String hostId, long vrf, Ipv4Address ip) {
77 HashMap<Long, RoutingInfo> routingInfoMapper = mapper.get(hostId);
79 Preconditions.checkNotNull(routingInfoMapper, "Routing protocol not created, can't add route entry");
81 RoutingInfo routingInfo = routingInfoMapper.get(vrf);
83 return routingInfo.ipAlreadyExistsinVrf(ip);