2 * Copyright (c) 2016, 2017 Red Hat, Inc. and others. 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.netvirt.ipv6service;
10 import com.google.common.collect.ImmutableBiMap;
11 import javax.annotation.PostConstruct;
12 import javax.inject.Inject;
13 import javax.inject.Singleton;
14 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
15 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
16 import org.opendaylight.genius.datastoreutils.AsyncClusteredDataTreeChangeListenerBase;
17 import org.opendaylight.netvirt.ipv6service.utils.Ipv6Constants;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.constants.rev150712.Dhcpv6Base;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.constants.rev150712.Dhcpv6Off;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.constants.rev150712.Dhcpv6Slaac;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.constants.rev150712.Dhcpv6Stateful;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.constants.rev150712.Dhcpv6Stateless;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.constants.rev150712.IpVersionBase;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.constants.rev150712.IpVersionV4;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.constants.rev150712.IpVersionV6;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.rev150712.Neutron;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.Subnets;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.subnets.rev150712.subnets.attributes.subnets.Subnet;
29 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
34 public class NeutronSubnetChangeListener extends AsyncClusteredDataTreeChangeListenerBase<Subnet,
35 NeutronSubnetChangeListener> {
36 private static final Logger LOG = LoggerFactory.getLogger(NeutronSubnetChangeListener.class);
37 private final DataBroker dataBroker;
38 private final IfMgr ifMgr;
40 private static final ImmutableBiMap<Class<? extends IpVersionBase>,String> IPV_MAP
41 = new ImmutableBiMap.Builder<Class<? extends IpVersionBase>,String>()
42 .put(IpVersionV4.class, Ipv6Constants.IP_VERSION_V4)
43 .put(IpVersionV6.class, Ipv6Constants.IP_VERSION_V6)
46 private static final ImmutableBiMap<Class<? extends Dhcpv6Base>,String> DHCPV6_MAP
47 = new ImmutableBiMap.Builder<Class<? extends Dhcpv6Base>,String>()
48 .put(Dhcpv6Off.class,Ipv6Constants.DHCPV6_OFF)
49 .put(Dhcpv6Stateful.class,Ipv6Constants.IPV6_DHCPV6_STATEFUL)
50 .put(Dhcpv6Slaac.class,Ipv6Constants.IPV6_SLAAC)
51 .put(Dhcpv6Stateless.class,Ipv6Constants.IPV6_DHCPV6_STATELESS)
55 public NeutronSubnetChangeListener(final DataBroker dataBroker, IfMgr ifMgr) {
56 this.dataBroker = dataBroker;
62 LOG.info("{} init", getClass().getSimpleName());
63 registerListener(LogicalDatastoreType.CONFIGURATION, dataBroker);
67 protected InstanceIdentifier<Subnet> getWildCardPath() {
68 return InstanceIdentifier.create(Neutron.class).child(Subnets.class).child(Subnet.class);
72 protected void add(InstanceIdentifier<Subnet> identifier, Subnet input) {
73 if (IPV_MAP.get(input.getIpVersion()).equals(Ipv6Constants.IP_VERSION_V6)) {
74 LOG.info("Add Subnet notification handler is invoked {} ", input);
75 String ipv6AddrMode = "";
76 if (input.getIpv6AddressMode() != null) {
77 ipv6AddrMode = DHCPV6_MAP.get(input.getIpv6AddressMode());
79 String ipv6RaMode = "";
80 if (input.getIpv6RaMode() != null) {
81 ipv6RaMode = DHCPV6_MAP.get(input.getIpv6RaMode());
83 ifMgr.addSubnet(input.getUuid(), input.getName(),
84 input.getTenantId(), input.getGatewayIp(), IPV_MAP.get(input.getIpVersion()),
85 input.getCidr(), ipv6AddrMode, ipv6RaMode);
90 protected void remove(InstanceIdentifier<Subnet> identifier, Subnet input) {
91 ifMgr.removeSubnet(input.getUuid());
95 protected void update(InstanceIdentifier<Subnet> identifier, Subnet original, Subnet update) {
96 LOG.debug("Update Subnet notification handler is invoked Original: {}, Update: {}", original, update);
100 protected NeutronSubnetChangeListener getDataTreeChangeListener() {
101 return NeutronSubnetChangeListener.this;