Add new API's for LLDP 05/48005/4
authorsenthil <senthil.b@tataelxsi.co.in>
Fri, 4 Nov 2016 17:26:49 +0000 (22:56 +0530)
committersenthil <senthil.b@tataelxsi.co.in>
Tue, 22 Nov 2016 17:40:48 +0000 (23:10 +0530)
  *Right now LLDP time period is hard coded
  *This patch enables to set the time period dynamically,
   which increases the performance of the CPU
  *Increase in CPU performance is observed clearly when we do scaling

Change-Id: I959e151c1e0f11799617bc3ae679cfb7539e764a
Signed-off-by: senthil <senthil.b@tataelxsi.co.in>
applications/lldp-speaker/src/main/java/org/opendaylight/openflowplugin/applications/lldpspeaker/LLDPSpeaker.java
applications/lldp-speaker/src/main/java/org/opendaylight/openflowplugin/applications/lldpspeaker/OperationalStatusChangeService.java
applications/lldp-speaker/src/main/yang/lldp-speaker.yang

index 5c0f71fe923e4f6a72faa032998a6952da9a4b19..33392842760917505066ee30d122a2f0fa05da46 100644 (file)
@@ -37,12 +37,13 @@ import org.slf4j.LoggerFactory;
 public class LLDPSpeaker implements AutoCloseable, NodeConnectorEventsObserver, Runnable {
     private static final Logger LOG = LoggerFactory.getLogger(LLDPSpeaker.class);
     private static final long LLDP_FLOOD_PERIOD = 5;
+    private long Current_Flood_Period = LLDP_FLOOD_PERIOD;
 
     private final PacketProcessingService packetProcessingService;
     private final ScheduledExecutorService scheduledExecutorService;
     private final Map<InstanceIdentifier<NodeConnector>, TransmitPacketInput> nodeConnectorMap =
             new ConcurrentHashMap<>();
-    private final ScheduledFuture<?> scheduledSpeakerTask;
+    private ScheduledFuture<?> scheduledSpeakerTask;
     private final MacAddress addressDestionation;
     private volatile OperStatus operationalStatus = OperStatus.RUN;
 
@@ -62,6 +63,18 @@ public class LLDPSpeaker implements AutoCloseable, NodeConnectorEventsObserver,
         return operationalStatus;
     }
 
+    public void setLldpFloodInterval(long time) {
+        this.Current_Flood_Period = time;
+        scheduledSpeakerTask.cancel(false);
+        scheduledSpeakerTask = this.scheduledExecutorService
+                     .scheduleAtFixedRate(this, time, time, TimeUnit.SECONDS);
+        LOG.info("LLDPSpeaker restarted, it will send LLDP frames each {} seconds", time);
+   }
+
+    public long getLldpFloodInterval() {
+        return Current_Flood_Period;
+    }
+
     public LLDPSpeaker(final PacketProcessingService packetProcessingService,
                        final ScheduledExecutorService scheduledExecutorService,
                        final MacAddress addressDestionation) {
index b322dbcbe3cbd7dc01bc6a1c53e4ea0637ba6c4a..702de995aa6710f945972a620558e08269ab62ae 100644 (file)
@@ -13,6 +13,9 @@ import java.util.concurrent.Future;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow.applications.lldp.speaker.rev141023.ChangeOperationalStatusInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow.applications.lldp.speaker.rev141023.GetOperationalStatusOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow.applications.lldp.speaker.rev141023.GetOperationalStatusOutputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow.applications.lldp.speaker.rev141023.SetLldpFloodIntervalInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow.applications.lldp.speaker.rev141023.GetLldpFloodIntervalOutput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow.applications.lldp.speaker.rev141023.GetLldpFloodIntervalOutputBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.openflow.applications.lldp.speaker.rev141023.LldpSpeakerService;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
@@ -40,4 +43,20 @@ public class OperationalStatusChangeService implements LldpSpeakerService {
         rpcResultBuilder.withResult(getOperationalStatusOutputBuilder.build());
         return Futures.immediateFuture(rpcResultBuilder.build());
     }
+
+    @Override
+    public Future<RpcResult<Void>> setLldpFloodInterval(final SetLldpFloodIntervalInput input) {
+        speakerInstance.setLldpFloodInterval(input.getInterval());
+        RpcResultBuilder<Void> rpcResultBuilder = RpcResultBuilder.success();
+        return Futures.immediateFuture(rpcResultBuilder.build());
+    }
+
+    @Override
+    public Future<RpcResult<GetLldpFloodIntervalOutput>> getLldpFloodInterval() {
+        RpcResultBuilder<GetLldpFloodIntervalOutput> rpcResultBuilder = RpcResultBuilder.success();
+        GetLldpFloodIntervalOutputBuilder getLldpFloodIntervalOutputBuilder = new GetLldpFloodIntervalOutputBuilder();
+        getLldpFloodIntervalOutputBuilder.setInterval(speakerInstance.getLldpFloodInterval());
+        rpcResultBuilder.withResult(getLldpFloodIntervalOutputBuilder.build());
+        return Futures.immediateFuture(rpcResultBuilder.build());
+    }
 }
index b04803217896fe03e468d9822d870ba03d07e984..f468b5b45457c7903c401d72100fd0dfc6268556 100644 (file)
@@ -38,4 +38,20 @@ module lldp-speaker {
             }
          }
     }
+    rpc set-lldp-flood-interval {
+        input {
+            leaf interval {
+               type int64;
+               description "Set LLDP_FLOOD_PERIOD";
+            }
+        }
+    }
+    rpc get-lldp-flood-interval {
+        output {
+            leaf interval {
+               type int64;
+               description "Get LLDP_FLOOD_PERIOD";
+            }
+        }
+    }
 }