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.event.manager;
11 import com.google.common.base.Preconditions;
12 import com.google.common.eventbus.Subscribe;
13 import org.opendaylight.groupbasedpolicy.renderer.vpp.event.GbpSubnetEvent;
14 import org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.loopback.LoopbackManager;
15 import org.opendaylight.groupbasedpolicy.renderer.vpp.lisp.mappers.SubnetUuidToGbpSubnetMapper;
16 import org.opendaylight.groupbasedpolicy.renderer.vpp.util.MountedDataBrokerProvider;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.vpp_renderer.rev160425.config.GbpSubnet;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
21 import javax.annotation.Nonnull;
24 * Created by Shakib Ahmed on 5/3/17.
26 public class GbpSubnetEventManager {
27 private static final Logger LOG = LoggerFactory.getLogger(GbpSubnetEventManager.class);
29 private SubnetUuidToGbpSubnetMapper subnetUuidToGbpSubnetInfoMapper;
30 private LoopbackManager loopbackManager;
32 public GbpSubnetEventManager(@Nonnull LoopbackManager loopbackManager) {
33 this.loopbackManager = loopbackManager;
34 this.subnetUuidToGbpSubnetInfoMapper = SubnetUuidToGbpSubnetMapper.getInstance();
38 public synchronized void gbpSubnetChanged(GbpSubnetEvent event) {
39 final GbpSubnet oldGbpSubnet = event.getBefore().orNull();
40 final GbpSubnet newGbpSubnet = event.getAfter().orNull();
42 LOG.debug("GbpSubnet information updated.\nPrevious: {}\nPresent: {}\n", oldGbpSubnet, newGbpSubnet);
44 switch (event.getDtoModificationType()) {
46 Preconditions.checkNotNull(newGbpSubnet);
47 processSubnetCreated(newGbpSubnet.getId(), newGbpSubnet);
50 Preconditions.checkNotNull(oldGbpSubnet);
51 Preconditions.checkNotNull(newGbpSubnet);
52 processSubnetDeleted(oldGbpSubnet.getId());
53 processSubnetCreated(newGbpSubnet.getId(), newGbpSubnet);
56 Preconditions.checkNotNull(oldGbpSubnet);
57 processSubnetDeleted(oldGbpSubnet.getId());
62 private void processSubnetCreated(String subnetUuid, GbpSubnet subnetInfo) {
63 subnetUuidToGbpSubnetInfoMapper.addSubnetInfo(subnetUuid, subnetInfo);
66 private void processSubnetDeleted(String subnetUuid) {
67 subnetUuidToGbpSubnetInfoMapper.removeSubnetInfo(subnetUuid);
68 loopbackManager.deleteLoopbackIfExists(subnetUuid);