use of org.onosproject.openflow.controller.Dpid in project onos by opennetworkinglab.
the class OplinkHandshakerUtil method getNeighbor.
private OplinkPortAdjacency getNeighbor(OFExpPortAdjacency ad) {
// Check input parameter
if (ad == null) {
return null;
}
// Get adjacency properties
for (OFExpPortAdjacencyId adid : ad.getProperties()) {
List<OFExpExtAdId> otns = adid.getAdId();
if (otns != null && otns.size() > 0) {
OFExpPortAdidOtn otn = (OFExpPortAdidOtn) otns.get(0);
// ITU-T G.7714 ETH MAC Format (in second 16 bytes of the following)
// |---------------------------------------------------------------------------|
// | Other format (16 bytes) |
// |---------------------------------------------------------------------------|
// | Header (2 bytes) | ID (4 BITS) | MAC (6 bytes) | Port (4 bytes) | Unused |
// |---------------------------------------------------------------------------|
ByteBuf buffer = Unpooled.buffer(OPSPEC_BYTES);
otn.getOpspec().write32Bytes(buffer);
long mac = buffer.getLong(OPSPEC_MAC_POS) << OPSPEC_ID_BITS >>> OPSPEC_MAC_BIT_OFF;
int port = (int) (buffer.getLong(OPSPEC_PORT_POS) << OPSPEC_ID_BITS >>> OPSPEC_PORT_BIT_OFF);
// constructed from MAC address
return new OplinkPortAdjacency(DeviceId.deviceId(Dpid.uri(new Dpid(mac))), PortNumber.portNumber(port));
}
}
// Returns null if no properties found
return null;
}
use of org.onosproject.openflow.controller.Dpid in project onos by opennetworkinglab.
the class OplinkPowerConfigUtil method getOpenFlowDevice.
/**
* Returns current switch known to this OF controller.
*
* @return current switch
*/
private OpenFlowSwitch getOpenFlowDevice() {
final DriverHandler handler = behaviour.handler();
final OpenFlowController controller = handler.get(OpenFlowController.class);
final Dpid dpid = Dpid.dpid(handler.data().deviceId().uri());
OpenFlowSwitch sw = controller.getSwitch(dpid);
if (sw == null || !sw.isConnected()) {
log.warn("OpenFlow handshaker driver not found or device is not connected, dpid = {}", dpid);
return null;
}
return sw;
}
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;
}
Aggregations