Created
May 14, 2013 17:57
-
-
Save fredhsu/5578042 to your computer and use it in GitHub Desktop.
Activator for mystats example with OpenDaylight
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.mystats; | |
import org.apache.felix.dm.Component; | |
import org.opendaylight.controller.sal.core.ComponentActivatorAbstractBase; | |
import org.slf4j.Logger; | |
import org.slf4j.LoggerFactory; | |
public class Activator extends ComponentActivatorAbstractBase { | |
protected static final Logger logger = LoggerFactory | |
.getLogger(Activator.class); | |
public void init() { | |
} | |
public void destroy() { | |
} | |
public Object[] getImplementations() { | |
Object[] res = { MyStats.class }; | |
return res; | |
} | |
public void configureInstance(Component c, Object imp, String containerName) { | |
if (imp.equals(MyStats.class)) { | |
// export the service | |
c.setInterface(new String[] { MyStats.class.getName() }, | |
null); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.mystats; | |
import org.opendaylight.controller.sal.core.Node; | |
import org.opendaylight.controller.sal.match.MatchType; | |
import org.opendaylight.controller.sal.reader.FlowOnNode; | |
import org.opendaylight.controller.sal.utils.ServiceHelper; | |
import org.opendaylight.controller.statisticsmanager.IStatisticsManager; | |
import org.opendaylight.controller.switchmanager.ISwitchManager; | |
import org.slf4j.Logger; | |
import org.slf4j.LoggerFactory; | |
/** | |
* Simple bundle to grab some statistics | |
* Fred Hsu | |
*/ | |
public class MyStats{ | |
private static final Logger log = LoggerFactory | |
.getLogger(MyStats.class); | |
public MyStats() { | |
} | |
void init() { | |
log.debug("INIT called!"); | |
} | |
void destroy() { | |
log.debug("DESTROY called!"); | |
} | |
void start() { | |
log.debug("START called!"); | |
getFlowStatistics(); | |
} | |
void stop() { | |
log.debug("STOP called!"); | |
} | |
void getFlowStatistics() { | |
String containerName = "default"; | |
IStatisticsManager statsManager = (IStatisticsManager) ServiceHelper | |
.getInstance(IStatisticsManager.class, containerName, this); | |
ISwitchManager switchManager = (ISwitchManager) ServiceHelper | |
.getInstance(ISwitchManager.class, containerName, this); | |
for (Node node : switchManager.getNodes()) { | |
System.out.println("Node: " + node); | |
for (FlowOnNode flow : statsManager.getFlows(node)) { | |
System.out.println(" DST: " | |
+ flow.getFlow().getMatch().getField(MatchType.NW_DST) | |
+ " Bytes: " + flow.getByteCount()); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment