Search in sources :

Example 6 with Dpid

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);
        }
    }
}
Also used : OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) OFPortDesc(org.projectfloodlight.openflow.protocol.OFPortDesc) DeviceId(org.onosproject.net.DeviceId) Dpid(org.onosproject.openflow.controller.Dpid) OpenFlowSwitch(org.onosproject.openflow.controller.OpenFlowSwitch) OFPort(org.projectfloodlight.openflow.types.OFPort) OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) Instruction(org.onosproject.net.flow.instructions.Instruction) OFPacketOut(org.projectfloodlight.openflow.protocol.OFPacketOut)

Example 7 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 8 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 9 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)

Example 10 with Dpid

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;
}
Also used : OpenFlowDeviceConfig(org.onosproject.openflow.config.OpenFlowDeviceConfig) DeviceId(org.onosproject.net.DeviceId) Dpid(org.onosproject.openflow.controller.Dpid) KeyStoreException(java.security.KeyStoreException) Certificate(java.security.cert.Certificate)

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