Search in sources :

Example 1 with Dpid

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;
}
Also used : Dpid(org.onosproject.openflow.controller.Dpid) OFExpExtAdId(org.projectfloodlight.openflow.protocol.OFExpExtAdId) OFExpPortAdidOtn(org.projectfloodlight.openflow.protocol.OFExpPortAdidOtn) OFExpPortAdjacencyId(org.projectfloodlight.openflow.protocol.OFExpPortAdjacencyId) ByteBuf(io.netty.buffer.ByteBuf) ConnectPoint(org.onosproject.net.ConnectPoint)

Example 2 with Dpid

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;
}
Also used : Dpid(org.onosproject.openflow.controller.Dpid) OpenFlowSwitch(org.onosproject.openflow.controller.OpenFlowSwitch) DriverHandler(org.onosproject.net.driver.DriverHandler) OpenFlowController(org.onosproject.openflow.controller.OpenFlowController)

Example 3 with Dpid

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;
}
Also used : OFPortModPropOptical(org.projectfloodlight.openflow.protocol.OFPortModPropOptical) OFPortMod(org.projectfloodlight.openflow.protocol.OFPortMod) DeviceId(org.onosproject.net.DeviceId) Dpid(org.onosproject.openflow.controller.Dpid) OpenFlowController(org.onosproject.openflow.controller.OpenFlowController) ArrayList(java.util.ArrayList) OFPortModProp(org.projectfloodlight.openflow.protocol.OFPortModProp) OFPortDesc(org.projectfloodlight.openflow.protocol.OFPortDesc) OpenFlowSwitch(org.onosproject.openflow.controller.OpenFlowSwitch)

Example 4 with Dpid

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();
}
Also used : Dpid(org.onosproject.openflow.controller.Dpid) OpenFlowSwitch(org.onosproject.openflow.controller.OpenFlowSwitch) OpenFlowController(org.onosproject.openflow.controller.OpenFlowController)

Example 5 with Dpid

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;
}
Also used : OpenFlowSwitchDriver(org.onosproject.openflow.controller.driver.OpenFlowSwitchDriver) DefaultDriverHandler(org.onosproject.net.driver.DefaultDriverHandler) Dpid(org.onosproject.openflow.controller.Dpid) Driver(org.onosproject.net.driver.Driver) OpenFlowSwitchDriver(org.onosproject.openflow.controller.driver.OpenFlowSwitchDriver) ItemNotFoundException(org.onlab.util.ItemNotFoundException) DefaultDriverData(org.onosproject.net.driver.DefaultDriverData)

Aggregations

Dpid (org.onosproject.openflow.controller.Dpid)22 OpenFlowSwitch (org.onosproject.openflow.controller.OpenFlowSwitch)17 OpenFlowController (org.onosproject.openflow.controller.OpenFlowController)5 DeviceId (org.onosproject.net.DeviceId)4 GroupId (org.onosproject.core.GroupId)3 OFPortDesc (org.projectfloodlight.openflow.protocol.OFPortDesc)3 ByteBuf (io.netty.buffer.ByteBuf)2 DefaultDriverData (org.onosproject.net.driver.DefaultDriverData)2 DefaultDriverHandler (org.onosproject.net.driver.DefaultDriverHandler)2 Driver (org.onosproject.net.driver.Driver)2 DriverHandler (org.onosproject.net.driver.DriverHandler)2 GroupBuckets (org.onosproject.net.group.GroupBuckets)2 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 Strings.isNullOrEmpty (com.google.common.base.Strings.isNullOrEmpty)1 Cache (com.google.common.cache.Cache)1 CacheBuilder (com.google.common.cache.CacheBuilder)1 RemovalCause (com.google.common.cache.RemovalCause)1 RemovalNotification (com.google.common.cache.RemovalNotification)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Lists (com.google.common.collect.Lists)1