X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=nexthopmgr%2Fnexthopmgr-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fvpnservice%2Fnexthopmgr%2FVpnInterfaceChangeListener.java;h=1245a12ad9da2699894aaa6dcf375946c75342fc;hb=cd331f15ad231c081bf3725fd10e8cfd39f58241;hp=855f387d3b8f7e4511977808291fd0adb61a4392;hpb=5d87e53cdbed3197a5035ae7452583bd5ae8c638;p=vpnservice.git diff --git a/nexthopmgr/nexthopmgr-impl/src/main/java/org/opendaylight/vpnservice/nexthopmgr/VpnInterfaceChangeListener.java b/nexthopmgr/nexthopmgr-impl/src/main/java/org/opendaylight/vpnservice/nexthopmgr/VpnInterfaceChangeListener.java index 855f387d..1245a12a 100644 --- a/nexthopmgr/nexthopmgr-impl/src/main/java/org/opendaylight/vpnservice/nexthopmgr/VpnInterfaceChangeListener.java +++ b/nexthopmgr/nexthopmgr-impl/src/main/java/org/opendaylight/vpnservice/nexthopmgr/VpnInterfaceChangeListener.java @@ -8,16 +8,12 @@ package org.opendaylight.vpnservice.nexthopmgr; import java.util.List; -import java.util.ArrayList; - import com.google.common.base.Optional; - import org.opendaylight.controller.md.sal.binding.api.DataBroker; import org.opendaylight.controller.md.sal.binding.api.DataChangeListener; import org.opendaylight.yangtools.concepts.ListenerRegistration; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.InstanceIdentifierBuilder; import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope; @@ -25,17 +21,13 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.l3vpn.rev130911.adjacency.l import org.opendaylight.yang.gen.v1.urn.opendaylight.l3vpn.rev130911.Adjacencies; import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.VpnInterfaces; import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterface; -import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterfaceKey; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface; -import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey; import org.opendaylight.vpnservice.nexthopmgr.AbstractDataChangeListener; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class VpnInterfaceChangeListener extends AbstractDataChangeListener implements AutoCloseable { +public class VpnInterfaceChangeListener extends AbstractDataChangeListener implements AutoCloseable { private static final Logger LOG = LoggerFactory.getLogger(VpnInterfaceChangeListener.class); private ListenerRegistration listenerRegistration; @@ -43,7 +35,7 @@ public class VpnInterfaceChangeListener extends AbstractDataChangeListener identifier, - VpnInterface vpnIf) { - LOG.info("key: " + identifier + ", value=" + vpnIf ); - - String vpnName = vpnIf.getVpnInstanceName(); - final VpnInterfaceKey key = identifier.firstKeyOf(VpnInterface.class, VpnInterfaceKey.class); - String interfaceName = key.getName(); - InstanceIdentifierBuilder idBuilder = - InstanceIdentifier.builder(Interfaces.class).child(Interface.class, new InterfaceKey(interfaceName)); - InstanceIdentifier id = idBuilder.build(); - Optional port = read(LogicalDatastoreType.CONFIGURATION, id); - if (port.isPresent()) { - //Interface interf = port.get(); - - //Read NextHops - InstanceIdentifier path = identifier.augmentation(Adjacencies.class); - Optional adjacencies = read(LogicalDatastoreType.CONFIGURATION, path); - - if (adjacencies.isPresent()) { - List nextHops = adjacencies.get().getAdjacency(); - List value = new ArrayList<>(); - - if (!nextHops.isEmpty()) { - LOG.info("NextHops are " + nextHops); - for (Adjacency nextHop : nextHops) { - nexthopManager.createLocalNextHop(interfaceName, vpnName, nextHop.getIpAddress()); - } - } - } + protected void add(InstanceIdentifier identifier, + Adjacencies adjs) { + + InstanceIdentifier vpnIfId = identifier.firstIdentifierOf(VpnInterface.class); + Optional vpnIf = read(LogicalDatastoreType.CONFIGURATION, vpnIfId); + VpnInterface vpnIfData = vpnIf.get(); + + List adjList = adjs.getAdjacency(); + for (Adjacency adjacency : adjList) { + nexthopManager.createLocalNextHop( + vpnIfData.getName(), + vpnIfData.getVpnInstanceName(), + adjacency.getIpAddress(), + adjacency.getMacAddress()); } + } + + + @Override + protected void remove(InstanceIdentifier identifier, + Adjacencies adjs) { + InstanceIdentifier vpnIfId = identifier.firstIdentifierOf(VpnInterface.class); + Optional vpnIf = read(LogicalDatastoreType.CONFIGURATION, vpnIfId); + VpnInterface vpnIfData = vpnIf.get(); + + List adjList = adjs.getAdjacency(); + for (Adjacency adjacency : adjList) { + nexthopManager.removeLocalNextHop(vpnIfData.getVpnInstanceName(), adjacency.getIpAddress()); + } + + } + @Override + protected void update(InstanceIdentifier identifier, + Adjacencies original, Adjacencies update) { + // TODO Auto-generated method stub } + private Optional read(LogicalDatastoreType datastoreType, InstanceIdentifier path) { @@ -122,21 +120,9 @@ public class VpnInterfaceChangeListener extends AbstractDataChangeListener getWildCardPath() { - return InstanceIdentifier.create(VpnInterfaces.class).child(VpnInterface.class); + private InstanceIdentifier getWildCardPath() { + return InstanceIdentifier.create(VpnInterfaces.class).child(VpnInterface.class).augmentation(Adjacencies.class); } - @Override - protected void remove(InstanceIdentifier identifier, - VpnInterface del) { - // TODO Auto-generated method stub - } - - @Override - protected void update(InstanceIdentifier identifier, - VpnInterface original, VpnInterface update) { - // TODO Auto-generated method stub - - } } \ No newline at end of file