app生命周期
@Activate
public void activate(ComponentContext context ) {
cfgService.registerProperties(getClass());
appId = coreService .registerApplication("org.onosproject.fwd");
packetService.addProcessor(processor , PacketProcessor.director(2));
topologyService.addListener(topologyListener );
readComponentConfiguration( context);
requestIntercepts();
log.info("Started" , appId .id());
}
@Deactivate
public void deactivate() {
cfgService.unregisterProperties(getClass(), false);
withdrawIntercepts();
flowRuleService.removeFlowRulesById(appId );
packetService.removeProcessor(processor );
topologyService.removeListener(topologyListener );
processor = null ;
log.info("Stopped" );
}
@Modified
public void modified(ComponentContext context ) {
readComponentConfiguration( context);
requestIntercepts();
}
常见功能函数
// Indicates whether this is a control packet, e.g. LLDP, BDDP
// 判断是否为控制数据包
private boolean isControlPacket(Ethernet eth ) {
short type = eth.getEtherType();
return type == Ethernet.TYPE_LLDP || type == Ethernet.TYPE_BSN;
}
// Indicated whether this is an IPv6 multicast packet.
// 判断是否为ipv6多播包
private boolean isIpv6Multicast(Ethernet eth ) {
return eth .getEtherType() == Ethernet.TYPE_IPV6 && eth.isMulticast();
}
// Selects a path from the given set that does not lead back to the
// specified port if possible.
// 在一个给定的path集合中选择一条不通过指定端口的路径
private Path pickForwardPathIfPossible(Set<Path> paths, PortNumber notToPort) {
Path lastPath = null ;
for (Path path : paths) {
lastPath = path ;
if (!path .src().port().equals(notToPort)) {
return path ;
}
}
return lastPath ;
}
// Floods t