use of org.onosproject.openflow.controller.Dpid in project onos by opennetworkinglab.
the class OpenFlowPacketProvider method emit.
@Override
public void emit(OutboundPacket packet) {
DeviceId devId = packet.sendThrough();
String scheme = devId.toString().split(":")[0];
if (!scheme.equals(this.id().scheme())) {
throw new IllegalArgumentException("Don't know how to handle Device with scheme " + scheme);
}
Dpid dpid = Dpid.dpid(devId.uri());
OpenFlowSwitch sw = controller.getSwitch(dpid);
if (sw == null) {
log.warn("Device {} isn't available?", devId);
return;
}
OFPort inPort;
if (packet.inPort() != null) {
inPort = portDesc(packet.inPort()).getPortNo();
} else {
inPort = OFPort.CONTROLLER;
}
// Ethernet eth = new Ethernet();
// eth.deserialize(packet.data().array(), 0, packet.data().array().length);
OFPortDesc p = null;
for (Instruction inst : packet.treatment().allInstructions()) {
if (inst.type().equals(Instruction.Type.OUTPUT)) {
p = portDesc(((OutputInstruction) inst).port());
OFPacketOut po = packetOut(sw, packet.data().array(), p.getPortNo(), inPort);
sw.sendMsg(po);
}
}
}
use of org.onosproject.openflow.controller.Dpid in project onos by opennetworkinglab.
the class OpenFlowPowerConfig method setPortTargetPower.
private boolean setPortTargetPower(PortNumber port, double power) {
DeviceId deviceId = handler().data().deviceId();
final Dpid dpid = dpid(deviceId.uri());
OpenFlowSwitch sw = handler().get(OpenFlowController.class).getSwitch(dpid);
if (sw == null || !sw.isConnected()) {
log.error("Failed to change port on device {}", deviceId);
return false;
}
boolean enable = false;
for (OFPortDesc pd : getPortDescs()) {
if (pd.getPortNo().getPortNumber() == port.toLong()) {
enable = pd.getConfig().contains(OFPortConfig.PORT_DOWN);
break;
}
}
OFPortMod.Builder pmb = makePortMod(sw, port, enable);
double configure = OFOpticalPortFeaturesSerializerVer14.TX_PWR_VAL;
OFPortModPropOptical.Builder property = sw.factory().buildPortModPropOptical();
property.setTxPwr((long) power);
List<OFPortModProp> properties = new ArrayList<>();
properties.add(property.build());
pmb.setProperties(properties);
sw.sendMsg(Collections.singletonList(pmb.build()));
// TODO: We would need to report false in case of port mod failure.
return true;
}
use of org.onosproject.openflow.controller.Dpid in project onos by opennetworkinglab.
the class OpenFlowPowerConfig method getPortDescs.
private List<OFPortDesc> getPortDescs() {
final Dpid dpid = dpid(handler().data().deviceId().uri());
OpenFlowSwitch sw = handler().get(OpenFlowController.class).getSwitch(dpid);
return sw.getPorts();
}
use of org.onosproject.openflow.controller.Dpid in project onos by opennetworkinglab.
the class Controller method getOFSwitchInstance.
/**
* Forward to the driver-manager to get an IOFSwitch instance.
*
* @param dpid data path id
* @param desc switch description
* @param ofv OpenFlow version
* @return switch instance
*/
protected OpenFlowSwitchDriver getOFSwitchInstance(long dpid, OFDescStatsReply desc, OFVersion ofv) {
Dpid dpidObj = new Dpid(dpid);
Driver driver;
try {
driver = driverService.getDriver(DeviceId.deviceId(Dpid.uri(dpidObj)));
} catch (ItemNotFoundException e) {
driver = driverService.getDriver(desc.getMfrDesc(), desc.getHwDesc(), desc.getSwDesc());
}
if (driver == null) {
log.error("No OpenFlow driver for {} : {}", dpidObj, desc);
return null;
}
log.info("Driver '{}' assigned to device {}", driver.name(), dpidObj);
if (!driver.hasBehaviour(OpenFlowSwitchDriver.class)) {
log.error("Driver {} does not support OpenFlowSwitchDriver behaviour", driver.name());
return null;
}
DefaultDriverHandler handler = new DefaultDriverHandler(new DefaultDriverData(driver, deviceId(uri(dpidObj))));
OpenFlowSwitchDriver ofSwitchDriver = driver.createBehaviour(handler, OpenFlowSwitchDriver.class);
ofSwitchDriver.init(dpidObj, desc, ofv);
ofSwitchDriver.setAgent(agent);
ofSwitchDriver.setRoleHandler(new RoleManager(ofSwitchDriver));
return ofSwitchDriver;
}
use of org.onosproject.openflow.controller.Dpid in project onos by opennetworkinglab.
the class Controller method isValidCertificate.
public boolean isValidCertificate(Long dpid, Certificate peerCert) {
if (!tlsParams.isTlsEnabled()) {
return true;
}
if (netCfgService == null) {
// netcfg service not available; accept any cert if not in strict mode
return tlsParams.mode == TlsMode.ENABLED;
}
DeviceId deviceId = DeviceId.deviceId(Dpid.uri(new Dpid(dpid)));
OpenFlowDeviceConfig config = netCfgService.getConfig(deviceId, OpenFlowDeviceConfig.class);
if (config == null) {
// Config not set for device, accept any cert if not in strict mode
return tlsParams.mode == TlsMode.ENABLED;
}
Optional<String> alias = config.keyAlias();
if (!alias.isPresent()) {
// Config for device does not specify a certificate chain, accept any cert if not in strict mode
return tlsParams.mode == TlsMode.ENABLED;
}
try {
Certificate configuredCert = keyStore.getCertificate(alias.get());
// TODO there's probably a better way to compare these
return Objects.deepEquals(peerCert, configuredCert);
} catch (KeyStoreException e) {
log.info("failed to load key", e);
}
return false;
}
Aggregations