Adapt hc2vpp to changes to interface events api 77/7977/1
authorMarek Gradzki <[email protected]>
Thu, 10 Aug 2017 11:17:01 +0000 (13:17 +0200)
committerMarek Gradzki <[email protected]>
Thu, 10 Aug 2017 11:18:04 +0000 (13:18 +0200)
Requires https://gerrit.fd.io/r/#/c/7925/

Change-Id: If627983bfcb0bf36ec1aa34ec863280e1f1bee36
Signed-off-by: Marek Gradzki <[email protected]>
v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/interfaces/InterfaceCustomizer.java
v3po/v3po2vpp/src/main/java/io/fd/hc2vpp/v3po/notification/InterfaceChangeNotificationProducer.java
v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/interfaces/InterfaceCustomizerTest.java
v3po/v3po2vpp/src/test/java/io/fd/hc2vpp/v3po/notification/InterfaceChangeNotificationProducerTest.java

index 336a661..10c8478 100644 (file)
@@ -99,8 +99,7 @@ public class InterfaceCustomizer extends FutureJVppCustomizer
     private void setInterfaceFlags(final InstanceIdentifier<Interface> id, final String swIfName, final int swIfIndex,
                                    final byte enabled) throws WriteFailedException {
         final CompletionStage<SwInterfaceSetFlagsReply> swInterfaceSetFlagsReplyFuture =
-                getFutureJVpp().swInterfaceSetFlags(
-                        getSwInterfaceSetFlagsInput(swIfIndex, enabled, (byte) 0 /* deleted */));
+                getFutureJVpp().swInterfaceSetFlags(getSwInterfaceSetFlagsInput(swIfIndex, enabled));
 
         LOG.debug("Updating interface flags for: {}, index: {}, enabled: {}", swIfName, swIfIndex, enabled);
 
@@ -109,13 +108,10 @@ public class InterfaceCustomizer extends FutureJVppCustomizer
                 swIfName, swIfIndex, enabled);
     }
 
-    private SwInterfaceSetFlags getSwInterfaceSetFlagsInput(final int swIfIndex, final byte enabled,
-                                                            final byte deleted) {
+    private SwInterfaceSetFlags getSwInterfaceSetFlagsInput(final int swIfIndex, final byte enabled) {
         final SwInterfaceSetFlags swInterfaceSetFlags = new SwInterfaceSetFlags();
         swInterfaceSetFlags.swIfIndex = swIfIndex;
         swInterfaceSetFlags.adminUpDown = enabled;
-        swInterfaceSetFlags.linkUpDown = enabled;
-        swInterfaceSetFlags.deleted = deleted;
         return swInterfaceSetFlags;
     }
 }
index ffab221..8ad7deb 100644 (file)
@@ -20,11 +20,16 @@ import com.google.common.base.Optional;
 import com.google.common.collect.Lists;
 import com.google.inject.Inject;
 import com.google.inject.name.Named;
+import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer;
+import io.fd.hc2vpp.common.translate.util.NamingContext;
 import io.fd.honeycomb.notification.ManagedNotificationProducer;
 import io.fd.honeycomb.notification.NotificationCollector;
 import io.fd.honeycomb.translate.MappingContext;
-import io.fd.hc2vpp.common.translate.util.JvppReplyConsumer;
-import io.fd.hc2vpp.common.translate.util.NamingContext;
+import io.fd.vpp.jvpp.VppBaseCallException;
+import io.fd.vpp.jvpp.core.dto.SwInterfaceEventNotification;
+import io.fd.vpp.jvpp.core.dto.WantInterfaceEvents;
+import io.fd.vpp.jvpp.core.dto.WantInterfaceEventsReply;
+import io.fd.vpp.jvpp.core.future.FutureJVppCore;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.concurrent.CompletionStage;
@@ -39,11 +44,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.InterfaceStateChangeBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.InterfaceStatus;
 import org.opendaylight.yangtools.yang.binding.Notification;
-import io.fd.vpp.jvpp.VppBaseCallException;
-import io.fd.vpp.jvpp.core.dto.SwInterfaceSetFlagsNotification;
-import io.fd.vpp.jvpp.core.dto.WantInterfaceEvents;
-import io.fd.vpp.jvpp.core.dto.WantInterfaceEventsReply;
-import io.fd.vpp.jvpp.core.future.FutureJVppCore;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -76,25 +76,25 @@ public final class InterfaceChangeNotificationProducer implements ManagedNotific
         LOG.trace("Starting interface notifications");
         enableDisableIfcNotifications(1);
         LOG.debug("Interface notifications started successfully");
-        notificationListenerReg = jvpp.getNotificationRegistry().registerSwInterfaceSetFlagsNotificationCallback(
-                swInterfaceSetFlagsNotification -> {
-                    LOG.trace("Interface notification received: {}", swInterfaceSetFlagsNotification);
+        notificationListenerReg = jvpp.getNotificationRegistry().registerSwInterfaceEventNotificationCallback(
+                swInterfaceEventNotification -> {
+                    LOG.trace("Interface notification received: {}", swInterfaceEventNotification);
                     // TODO HONEYCOMB-166 this should be lazy
-                    collector.onNotification(transformNotification(swInterfaceSetFlagsNotification));
+                    collector.onNotification(transformNotification(swInterfaceEventNotification));
                 }
         );
     }
 
-    private Notification transformNotification(final SwInterfaceSetFlagsNotification swInterfaceSetFlagsNotification) {
-        if (swInterfaceSetFlagsNotification.deleted == 1) {
-            return new InterfaceDeletedBuilder().setName(getIfcName(swInterfaceSetFlagsNotification)).build();
+    private Notification transformNotification(final SwInterfaceEventNotification swInterfaceEventNotification) {
+        if (swInterfaceEventNotification.deleted == 1) {
+            return new InterfaceDeletedBuilder().setName(getIfcName(swInterfaceEventNotification)).build();
         } else {
             return new InterfaceStateChangeBuilder()
-                    .setName(getIfcName(swInterfaceSetFlagsNotification))
-                    .setAdminStatus(swInterfaceSetFlagsNotification.adminUpDown == 1
+                    .setName(getIfcName(swInterfaceEventNotification))
+                    .setAdminStatus(swInterfaceEventNotification.adminUpDown == 1
                             ? InterfaceStatus.Up
                             : InterfaceStatus.Down)
-                    .setOperStatus(swInterfaceSetFlagsNotification.linkUpDown == 1
+                    .setOperStatus(swInterfaceEventNotification.linkUpDown == 1
                             ? InterfaceStatus.Up
                             : InterfaceStatus.Down)
                     .build();
@@ -108,12 +108,12 @@ public final class InterfaceChangeNotificationProducer implements ManagedNotific
      * <p/>
      * In case mapping is not available, index is used as name.
      */
-    private InterfaceNameOrIndex getIfcName(final SwInterfaceSetFlagsNotification swInterfaceSetFlagsNotification) {
+    private InterfaceNameOrIndex getIfcName(final SwInterfaceEventNotification swInterfaceEventNotification) {
         final Optional<String> optionalName =
-                interfaceContext.getNameIfPresent(swInterfaceSetFlagsNotification.swIfIndex, mappingContext);
+                interfaceContext.getNameIfPresent(swInterfaceEventNotification.swIfIndex, mappingContext);
         return optionalName.isPresent()
                 ? new InterfaceNameOrIndex(optionalName.get())
-                : new InterfaceNameOrIndex((long) swInterfaceSetFlagsNotification.swIfIndex);
+                : new InterfaceNameOrIndex((long) swInterfaceEventNotification.swIfIndex);
     }
 
     @Override
index 311889d..d332118 100644 (file)
@@ -107,9 +107,7 @@ public class InterfaceCustomizerTest extends WriterCustomizerTest implements Byt
 
     private SwInterfaceSetFlags expectedRequest(final boolean enabled) {
         final SwInterfaceSetFlags request = new SwInterfaceSetFlags();
-        request.deleted = 0;
         request.adminUpDown = booleanToByte(enabled);
-        request.linkUpDown = booleanToByte(enabled);
         request.swIfIndex = IF_INDEX;
         return request;
     }
index 4751162..7605d42 100644 (file)
@@ -22,11 +22,17 @@ import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 
-import io.fd.honeycomb.notification.NotificationCollector;
-import io.fd.honeycomb.translate.MappingContext;
+import io.fd.hc2vpp.common.test.util.FutureProducer;
 import io.fd.hc2vpp.common.test.util.NamingContextHelper;
 import io.fd.hc2vpp.common.translate.util.NamingContext;
-import io.fd.hc2vpp.common.test.util.FutureProducer;
+import io.fd.honeycomb.notification.NotificationCollector;
+import io.fd.honeycomb.translate.MappingContext;
+import io.fd.vpp.jvpp.core.callback.SwInterfaceEventNotificationCallback;
+import io.fd.vpp.jvpp.core.dto.SwInterfaceEventNotification;
+import io.fd.vpp.jvpp.core.dto.WantInterfaceEvents;
+import io.fd.vpp.jvpp.core.dto.WantInterfaceEventsReply;
+import io.fd.vpp.jvpp.core.future.FutureJVppCore;
+import io.fd.vpp.jvpp.core.notification.CoreNotificationRegistry;
 import org.junit.Before;
 import org.junit.Test;
 import org.mockito.ArgumentCaptor;
@@ -34,12 +40,6 @@ import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.InterfaceStateChange;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.v3po.rev170607.InterfaceStatus;
-import io.fd.vpp.jvpp.core.callback.SwInterfaceSetFlagsNotificationCallback;
-import io.fd.vpp.jvpp.core.dto.SwInterfaceSetFlagsNotification;
-import io.fd.vpp.jvpp.core.dto.WantInterfaceEvents;
-import io.fd.vpp.jvpp.core.dto.WantInterfaceEventsReply;
-import io.fd.vpp.jvpp.core.future.FutureJVppCore;
-import io.fd.vpp.jvpp.core.notification.CoreNotificationRegistry;
 
 public class InterfaceChangeNotificationProducerTest implements FutureProducer, NamingContextHelper {
 
@@ -59,14 +59,14 @@ public class InterfaceChangeNotificationProducerTest implements FutureProducer,
     @Mock
     private AutoCloseable notificationListenerReg;
 
-    private ArgumentCaptor<SwInterfaceSetFlagsNotificationCallback> callbackArgumentCaptor;
+    private ArgumentCaptor<SwInterfaceEventNotificationCallback> callbackArgumentCaptor;
 
     @Before
     public void setUp() throws Exception {
         MockitoAnnotations.initMocks(this);
         doReturn(notificationRegistry).when(jVpp).getNotificationRegistry();
-        callbackArgumentCaptor = ArgumentCaptor.forClass(SwInterfaceSetFlagsNotificationCallback.class);
-        doReturn(notificationListenerReg).when(notificationRegistry).registerSwInterfaceSetFlagsNotificationCallback(
+        callbackArgumentCaptor = ArgumentCaptor.forClass(SwInterfaceEventNotificationCallback.class);
+        doReturn(notificationListenerReg).when(notificationRegistry).registerSwInterfaceEventNotificationCallback(
             callbackArgumentCaptor.capture());
         defineMapping(mappingContext, IFACE_NAME, IFACE_ID, IFC_CTX_NAME);
         doReturn(future(new WantInterfaceEventsReply())).when(jVpp).wantInterfaceEvents(any(WantInterfaceEvents.class));
@@ -80,8 +80,8 @@ public class InterfaceChangeNotificationProducerTest implements FutureProducer,
         interfaceChangeNotificationProducer.start(collector);
         verify(jVpp).wantInterfaceEvents(any(WantInterfaceEvents.class));
         verify(jVpp).getNotificationRegistry();
-        verify(notificationRegistry).registerSwInterfaceSetFlagsNotificationCallback(any(
-            SwInterfaceSetFlagsNotificationCallback.class));
+        verify(notificationRegistry).registerSwInterfaceEventNotificationCallback(any(
+                SwInterfaceEventNotificationCallback.class));
 
         interfaceChangeNotificationProducer.stop();
         verify(jVpp, times(2)).wantInterfaceEvents(any(WantInterfaceEvents.class));
@@ -95,12 +95,12 @@ public class InterfaceChangeNotificationProducerTest implements FutureProducer,
 
         interfaceChangeNotificationProducer.start(collector);
 
-        final SwInterfaceSetFlagsNotification swInterfaceSetFlagsNotification = new SwInterfaceSetFlagsNotification();
+        final SwInterfaceEventNotification swInterfaceSetFlagsNotification = new SwInterfaceEventNotification();
         swInterfaceSetFlagsNotification.deleted = 0;
         swInterfaceSetFlagsNotification.swIfIndex = IFACE_ID;
         swInterfaceSetFlagsNotification.adminUpDown = 1;
         swInterfaceSetFlagsNotification.linkUpDown = 1;
-        callbackArgumentCaptor.getValue().onSwInterfaceSetFlagsNotification(swInterfaceSetFlagsNotification);
+        callbackArgumentCaptor.getValue().onSwInterfaceEventNotification(swInterfaceSetFlagsNotification);
         final ArgumentCaptor<InterfaceStateChange> notificationCaptor =
             ArgumentCaptor.forClass(InterfaceStateChange.class);
         verify(collector).onNotification(notificationCaptor.capture());