use of org.onosproject.ofagent.api.OFSwitch in project onos by opennetworkinglab.
the class OFSwitchListCommand method doExecute.
@Override
protected void doExecute() {
OFSwitchService service = get(OFSwitchService.class);
Set<OFSwitch> ofSwitches;
if (networkId != NetworkId.NONE.id()) {
ofSwitches = service.ofSwitches(NetworkId.networkId(networkId));
} else {
ofSwitches = service.ofSwitches();
}
print(FORMAT, "DPID", "Connected controllers");
ofSwitches.forEach(ofSwitch -> {
Set<String> channels = ofSwitch.controllerChannels().stream().map(channel -> channel.remoteAddress().toString()).collect(Collectors.toSet());
print(FORMAT, ofSwitch.dpid(), channels);
});
}
use of org.onosproject.ofagent.api.OFSwitch in project onos by opennetworkinglab.
the class OFSwitchManager method addOFSwitch.
private void addOFSwitch(NetworkId networkId, DeviceId deviceId) {
OFSwitch ofSwitch = DefaultOFSwitch.of(dpidWithDeviceId(deviceId), DEFAULT_CAPABILITIES, networkId, deviceId, virtualNetService.getServiceDirectory());
ofSwitchMap.put(deviceId, ofSwitch);
log.info("Added virtual OF switch for {}", deviceId);
OFAgent ofAgent = ofAgentService.agent(networkId);
if (ofAgent == null) {
log.error("OFAgent for network {} does not exist", networkId);
return;
}
if (ofAgent.state() == STARTED) {
connectController(ofSwitch, ofAgent.controllers());
}
}
use of org.onosproject.ofagent.api.OFSwitch in project onos by opennetworkinglab.
the class OFSwitchManager method deleteOFSwitch.
private void deleteOFSwitch(DeviceId deviceId) {
OFSwitch ofSwitch = ofSwitchMap.get(deviceId);
ofSwitch.controllerChannels().forEach(ChannelOutboundInvoker::disconnect);
ofSwitchMap.remove(deviceId);
log.info("Removed virtual OFSwitch for {}", deviceId);
}
use of org.onosproject.ofagent.api.OFSwitch in project onos by opennetworkinglab.
the class DefaultOFSwitch method processLldp.
@Override
public void processLldp(Channel channel, OFMessage msg) {
log.trace("processLldp msg{}", msg);
// For each output port, look up neighbour port.
// If neighbour port exists, have the neighbour switch send lldp response.
// Modeled after how OpenVirtex handles lldp from external controller.
OFPacketOut ofPacketOut = (OFPacketOut) msg;
List<OFAction> actions = ofPacketOut.getActions();
for (final OFAction action : actions) {
OFActionType actionType = action.getType();
if (actionType.equals(OFActionType.OUTPUT)) {
OFActionOutput ofActionOutput = (OFActionOutput) action;
OFPort ofPort = ofActionOutput.getPort();
ConnectPoint neighbourCp = ofSwitchService.neighbour(networkId, deviceId, PortNumber.portNumber(ofPort.getPortNumber()));
if (neighbourCp == null) {
log.trace("No neighbour found for {} {}", deviceId, ofPort);
continue;
}
OFSwitch neighbourSwitch = ofSwitchService.ofSwitch(networkId, neighbourCp.deviceId());
neighbourSwitch.sendLldpResponse(ofPacketOut, neighbourCp.port());
}
}
}
use of org.onosproject.ofagent.api.OFSwitch in project onos by opennetworkinglab.
the class OFSwitchManager method processOFAgentStarted.
private void processOFAgentStarted(OFAgent ofAgent) {
devices(ofAgent.networkId()).forEach(deviceId -> {
OFSwitch ofSwitch = ofSwitchMap.get(deviceId);
if (ofSwitch != null) {
connectController(ofSwitch, ofAgent.controllers());
}
});
DeviceService deviceService = virtualNetService.get(ofAgent.networkId(), DeviceService.class);
deviceService.addListener(deviceListener);
PacketService packetService = virtualNetService.get(ofAgent.networkId(), PacketService.class);
packetService.addProcessor(packetProcessor, PacketProcessor.director(0));
FlowRuleService flowRuleService = virtualNetService.get(ofAgent.networkId(), FlowRuleService.class);
flowRuleService.addListener(flowRuleListener);
}
Aggregations