Java 类org.projectfloodlight.openflow.protocol.OFPortMod 实例源码

项目:onos    文件:OpenFlowPowerConfig.java   
private OFPortMod.Builder makePortMod(OpenFlowSwitch sw, PortNumber portNumber,
                            boolean enable) {
    OFPortMod.Builder pmb = sw.factory().buildPortMod();
    OFPort port = OFPort.of((int) portNumber.toLong());
    pmb.setPortNo(port);
    Set<OFPortConfig> portConfig = EnumSet.noneOf(OFPortConfig.class);
    if (!enable) {
        portConfig.add(OFPortConfig.PORT_DOWN);
    }
    pmb.setConfig(portConfig);
    Set<OFPortConfig> portMask = EnumSet.noneOf(OFPortConfig.class);
    portMask.add(OFPortConfig.PORT_DOWN);
    pmb.setMask(portMask);
    pmb.setAdvertise(0x0);
    for (OFPortDesc pd : sw.getPorts()) {
        if (pd.getPortNo().equals(port)) {
            pmb.setHwAddr(pd.getHwAddr());
            break;
        }
    }
    return pmb;
}
项目:athena    文件:OpenFlowDeviceProvider.java   
@Override
public void changePortState(DeviceId deviceId, PortNumber portNumber,
                            boolean enable) {
    final Dpid dpid = dpid(deviceId.uri());
    OpenFlowSwitch sw = controller.getSwitch(dpid);
    if (sw == null || !sw.isConnected()) {
        LOG.error("Failed to change portState on device {}", deviceId);
        return;
    }
    OFPortMod.Builder pmb = sw.factory().buildPortMod();
    OFPort port = OFPort.of((int) portNumber.toLong());
    pmb.setPortNo(port);
    if (enable) {
        pmb.setConfig(0x0); // port_down bit 0
    } else {
        pmb.setConfig(0x1); // port_down bit 1
    }
    pmb.setMask(0x1);
    pmb.setAdvertise(0x0);
    for (OFPortDesc pd : sw.getPorts()) {
        if (pd.getPortNo().equals(port)) {
            pmb.setHwAddr(pd.getHwAddr());
            break;
        }
    }
    sw.sendMsg(Collections.singletonList(pmb.build()));
}
项目:onos    文件:OpenFlowPowerConfig.java   
private boolean setPortTargetPower(PortNumber port, long 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);
    long configure = OFOpticalPortFeaturesSerializerVer14.TX_PWR_VAL;
    OFPortModPropOptical.Builder property = sw.factory().buildPortModPropOptical();
    property.setTxPwr(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;
}
项目:onos    文件:OpenFlowDeviceProvider.java   
@Override
public void changePortState(DeviceId deviceId, PortNumber portNumber,
                            boolean enable) {
    final Dpid dpid = dpid(deviceId.uri());
    OpenFlowSwitch sw = controller.getSwitch(dpid);
    if (sw == null || !sw.isConnected()) {
        LOG.error("Failed to change portState on device {}", deviceId);
        return;
    }
    OFPortMod.Builder pmb = sw.factory().buildPortMod();
    OFPort port = OFPort.of((int) portNumber.toLong());
    pmb.setPortNo(port);
    Set<OFPortConfig> portConfig = EnumSet.noneOf(OFPortConfig.class);
    if (!enable) {
        portConfig.add(OFPortConfig.PORT_DOWN);
    }
    pmb.setConfig(portConfig);
    Set<OFPortConfig> portMask = EnumSet.noneOf(OFPortConfig.class);
    portMask.add(OFPortConfig.PORT_DOWN);
    pmb.setMask(portMask);
    pmb.setAdvertise(0x0);
    for (OFPortDesc pd : sw.getPorts()) {
        if (pd.getPortNo().equals(port)) {
            pmb.setHwAddr(pd.getHwAddr());
            break;
        }
    }
    sw.sendMsg(Collections.singletonList(pmb.build()));
}
项目:onos    文件:DefaultOFSwitch.java   
private void processPortMod(OFPortMod portMod) {
    // process specified port
    PortNumber portNumber = PortNumber.portNumber(portMod.getPortNo().getPortNumber());
    boolean disablePort = portMod.getConfig().contains(OFPortConfig.PORT_DOWN);
    log.debug("processing PORT_MOD message - setting port {} state to {}",
              portNumber, !disablePort);
    virtualNetworkAdminService.updatePortState(networkId, deviceId, portNumber, !disablePort);
    // TODO what side effects (e.g. cleaning flow mods) needs to be handled?
}
项目:onos    文件:DefaultOFSwitch.java   
@Override
public void processControllerCommand(Channel channel, OFMessage msg) {

    OFControllerRole myRole = role(channel);
    if (OFControllerRole.ROLE_SLAVE.equals(myRole)) {
        OFBadRequestErrorMsg errorMsg = FACTORY.errorMsgs()
                .buildBadRequestErrorMsg()
                .setXid(msg.getXid())
                .setCode(OFBadRequestCode.IS_SLAVE)
                .build();
        channel.writeAndFlush(Collections.singletonList(errorMsg));
        return;
    }

    switch (msg.getType()) {
        case PORT_MOD:
            OFPortMod portMod = (OFPortMod) msg;
            processPortMod(portMod);
            break;
        case FLOW_MOD:
            OFFlowMod flowMod = (OFFlowMod) msg;
            processFlowMod(flowMod);
            break;
        case GROUP_MOD:
            OFGroupMod groupMod = (OFGroupMod) msg;
            processGroupMod(groupMod);
            break;
        case METER_MOD:
            OFMeterMod meterMod = (OFMeterMod) msg;
            processMeterMod(meterMod, channel);
            break;
        case TABLE_MOD:
            log.debug("processControllerCommand: {} not yet supported for {}",
                      msg.getType(), msg);
            break;
        default:
            log.warn("Unexpected message {} received for switch {}",
                     msg.getType(), this);
    }
}
项目:fast-failover-demo    文件:FastFailoverDemo.java   
private void usePathA() {
    /*
     * Take down path B ports at sw1 and sw3
     */
    IOFSwitch sw = switchService.getSwitch(dpid1);
    /* Set down */
    OFPortMod portMod = sw.getOFFactory().buildPortMod()
            .setPortNo(link_dpid1_to_dpid2b.getSrcPort())
            .setConfig(portDown(sw))
            .setMask(portDown(sw))
            .setHwAddr(sw.getPort(link_dpid1_to_dpid2b.getSrcPort()).getHwAddr())
            .build();
    sw.write(portMod);
    /* Set up */
    portMod = sw.getOFFactory().buildPortMod()
            .setPortNo(link_dpid1_to_dpid2a.getSrcPort())
            .setConfig(0)
            .setMask(portDown(sw))
            .setHwAddr(sw.getPort(link_dpid1_to_dpid2a.getSrcPort()).getHwAddr())
            .build();
    sw.write(portMod);

    sw = switchService.getSwitch(dpid3);
    /* Set down */
    portMod = sw.getOFFactory().buildPortMod()
            .setPortNo(link_dpid2b_to_dpid3.getDstPort())
            .setConfig(portDown(sw))
            .setMask(portDown(sw))
            .setHwAddr(sw.getPort(link_dpid2b_to_dpid3.getDstPort()).getHwAddr())
            .build();
    sw.write(portMod);
    /* Set up */
    portMod = sw.getOFFactory().buildPortMod()
            .setPortNo(link_dpid2a_to_dpid3.getDstPort())
            .setConfig(0)
            .setMask(portDown(sw))
            .setHwAddr(sw.getPort(link_dpid2a_to_dpid3.getDstPort()).getHwAddr())
            .build();
    sw.write(portMod);

    log.info("Took down ports on path sw1--sw2b--sw3 and brought up ports on sw1--sw2a--sw3");
}
项目:fast-failover-demo    文件:FastFailoverDemo.java   
private void usePathB() {
    /*
     * Take down path B ports at sw1 and sw3
     */
    IOFSwitch sw = switchService.getSwitch(dpid1);
    /* Set down */
    OFPortMod portMod = sw.getOFFactory().buildPortMod()
            .setPortNo(link_dpid1_to_dpid2a.getSrcPort())
            .setConfig(portDown(sw))
            .setMask(portDown(sw))
            .setHwAddr(sw.getPort(link_dpid1_to_dpid2a.getSrcPort()).getHwAddr())
            .build();
    sw.write(portMod);
    /* Set up */
    portMod = sw.getOFFactory().buildPortMod()
            .setPortNo(link_dpid1_to_dpid2b.getSrcPort())
            .setConfig(0)
            .setMask(portDown(sw))
            .setHwAddr(sw.getPort(link_dpid1_to_dpid2b.getSrcPort()).getHwAddr())
            .build();
    sw.write(portMod);

    sw = switchService.getSwitch(dpid3);
    /* Set down */
    portMod = sw.getOFFactory().buildPortMod()
            .setPortNo(link_dpid2a_to_dpid3.getDstPort())
            .setConfig(portDown(sw))
            .setMask(portDown(sw))
            .setHwAddr(sw.getPort(link_dpid2a_to_dpid3.getDstPort()).getHwAddr())
            .build();
    sw.write(portMod);
    /* Set up */
    portMod = sw.getOFFactory().buildPortMod()
            .setPortNo(link_dpid2b_to_dpid3.getDstPort())
            .setConfig(0)
            .setMask(portDown(sw))
            .setHwAddr(sw.getPort(link_dpid2b_to_dpid3.getDstPort()).getHwAddr())
            .build();
    sw.write(portMod);

    log.info("Took down ports on path sw1--sw2a--sw3 and brought up ports on sw1--sw2b--sw3");
}