2

I have method that receives packets from switch to floodlight controller in SDN which is mean this method is triggered for every new coming packet. I want to calculate the packet per second in that method.

This is my attempt; it is correct?

int CLoad,avergeLoad =0;
final String switchId = sw.getStringId();
        CLoad = CLoad + 1;
        avergeLoad = CLoad;
        loadTable.put(switchId, avergeLoad);
        ScheduledThreadPoolExecutor exec = new ScheduledThreadPoolExecutor(1);
        exec.scheduleAtFixedRate(new Runnable() 
               {
                public void run() 
                  {
                    avergeLoad =(avergeLoad + CLoad)/2;
                loadTable.put(switchId, avergeLoad);
                   CLoad=0;
                  }
               }, 40, 1000, TimeUnit.SECONDS); 
pnuts
  • 58,317
  • 11
  • 87
  • 139
user1888020
  • 67
  • 1
  • 9
  • 1
    This shouldn't even compile. You are referencing an unassigned variable. It's not clear what you are trying to do, and no one could say whether it's correct even after making it compilable. – erickson Nov 21 '15 at 23:26

2 Answers2

2

You could use Metrics meter

Meters measure the rate of the events in a few different ways. The mean rate is the average rate of events. It’s generally useful for trivia, but as it represents the total rate for your application’s entire lifetime (e.g., the total number of requests handled, divided by the number of seconds the process has been running), it doesn’t offer a sense of recency. Luckily, meters also record three different exponentially-weighted moving average rates: the 1-, 5-, and 15-minute moving averages.

Maven:

<dependency>
    <groupId>io.dropwizard.metrics</groupId>
    <artifactId>metrics-core</artifactId>
    <version>3.1.2</version>
</dependency>

Sample code:

//Setup the reporter
ConsoleReporter reporter = ConsoleReporter.forRegistry(metrics)
       .convertRatesTo(TimeUnit.SECONDS)
       .convertDurationsTo(TimeUnit.MILLISECONDS)
       .build();
   reporter.start(1, TimeUnit.SECONDS);

//Initialize Metrics Metter
final Meter getRequests = registry.meter(name(WebProxy.class, "get-requests", "requests"));

// Mark when event occurs
getRequests.mark();

Ref:

  1. Getting started
  2. Metrics meter
Tho
  • 23,158
  • 6
  • 60
  • 47
0

You could use Openflowplugin project implementation and adapt it on your need. It contains a Statistic Manager module that gets a lot of helpful information about flows, ports, meter, queue and etc.

Reference: https://wiki.opendaylight.org/view/OpenDaylight_OpenFlow_Plugin:Statistics

Icaro Camelo
  • 382
  • 1
  • 10