Search in sources :

Example 6 with OpenFlowSwitch

use of org.onosproject.openflow.controller.OpenFlowSwitch 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 7 with OpenFlowSwitch

use of org.onosproject.openflow.controller.OpenFlowSwitch 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 8 with OpenFlowSwitch

use of org.onosproject.openflow.controller.OpenFlowSwitch in project onos by opennetworkinglab.

the class OpenFlowControllerImplTest method testAddRemoveConnectedSwitch.

/**
 * Tests adding and removing connected switches.
 */
@Test
public void testAddRemoveConnectedSwitch() {
    // test adding connected switches
    boolean addSwitch1 = agent.addConnectedSwitch(dpid1, switch1);
    assertThat(addSwitch1, is(true));
    boolean addSwitch2 = agent.addConnectedSwitch(dpid2, switch2);
    assertThat(addSwitch2, is(true));
    boolean addSwitch3 = agent.addConnectedSwitch(dpid3, switch3);
    assertThat(addSwitch3, is(true));
    // Make sure the listener add callbacks fired
    assertThat(switchListener.addedDpids, hasSize(3));
    assertThat(switchListener.addedDpids, hasItems(dpid1, dpid2, dpid3));
    // Test adding a switch twice - it should fail
    boolean addBadSwitch1 = agent.addConnectedSwitch(dpid1, switch1);
    assertThat(addBadSwitch1, is(false));
    assertThat(controller.connectedSwitches.size(), is(3));
    // test querying the switch list
    Stream<OpenFlowSwitch> fetchedSwitches = makeIntoStream(controller.getSwitches());
    long switchCount = fetchedSwitches.count();
    assertThat(switchCount, is(3L));
    // test querying the individual switch
    OpenFlowSwitch queriedSwitch = controller.getSwitch(dpid1);
    assertThat(queriedSwitch, is(switch1));
    // Remove a switch
    agent.removeConnectedSwitch(dpid3);
    Stream<OpenFlowSwitch> fetchedSwitchesAfterRemove = makeIntoStream(controller.getSwitches());
    long switchCountAfterRemove = fetchedSwitchesAfterRemove.count();
    assertThat(switchCountAfterRemove, is(2L));
    // Make sure the listener delete callbacks fired
    assertThat(switchListener.removedDpids, hasSize(1));
    assertThat(switchListener.removedDpids, hasItems(dpid3));
    // test querying the removed switch
    OpenFlowSwitch queriedSwitchAfterRemove = controller.getSwitch(dpid3);
    assertThat(queriedSwitchAfterRemove, nullValue());
}
Also used : OpenFlowSwitch(org.onosproject.openflow.controller.OpenFlowSwitch) Test(org.junit.Test)

Example 9 with OpenFlowSwitch

use of org.onosproject.openflow.controller.OpenFlowSwitch in project onos by opennetworkinglab.

the class OpenFlowControllerImplTest method testMasterSwitch.

/**
 * Tests adding master switches.
 */
@Test
public void testMasterSwitch() {
    agent.addConnectedSwitch(dpid1, switch1);
    agent.transitionToMasterSwitch(dpid1);
    Stream<OpenFlowSwitch> fetchedMasterSwitches = makeIntoStream(controller.getMasterSwitches());
    assertThat(fetchedMasterSwitches.count(), is(1L));
    Stream<OpenFlowSwitch> fetchedActivatedSwitches = makeIntoStream(controller.getEqualSwitches());
    assertThat(fetchedActivatedSwitches.count(), is(0L));
    OpenFlowSwitch fetchedSwitch1 = controller.getMasterSwitch(dpid1);
    assertThat(fetchedSwitch1, is(switch1));
    agent.addConnectedSwitch(dpid2, switch2);
    boolean addSwitch2 = agent.addActivatedMasterSwitch(dpid2, switch2);
    assertThat(addSwitch2, is(true));
    OpenFlowSwitch fetchedSwitch2 = controller.getMasterSwitch(dpid2);
    assertThat(fetchedSwitch2, is(switch2));
}
Also used : OpenFlowSwitch(org.onosproject.openflow.controller.OpenFlowSwitch) Test(org.junit.Test)

Example 10 with OpenFlowSwitch

use of org.onosproject.openflow.controller.OpenFlowSwitch in project onos by opennetworkinglab.

the class OpenFlowControllerImplTest method testEqualSwitch.

/**
 * Tests adding equal switches.
 */
@Test
public void testEqualSwitch() {
    agent.addConnectedSwitch(dpid1, switch1);
    agent.transitionToEqualSwitch(dpid1);
    Stream<OpenFlowSwitch> fetchedEqualSwitches = makeIntoStream(controller.getEqualSwitches());
    assertThat(fetchedEqualSwitches.count(), is(1L));
    Stream<OpenFlowSwitch> fetchedActivatedSwitches = makeIntoStream(controller.getMasterSwitches());
    assertThat(fetchedActivatedSwitches.count(), is(0L));
    OpenFlowSwitch fetchedSwitch1 = controller.getEqualSwitch(dpid1);
    assertThat(fetchedSwitch1, is(switch1));
    agent.addConnectedSwitch(dpid2, switch2);
    boolean addSwitch2 = agent.addActivatedEqualSwitch(dpid2, switch2);
    assertThat(addSwitch2, is(true));
    OpenFlowSwitch fetchedSwitch2 = controller.getEqualSwitch(dpid2);
    assertThat(fetchedSwitch2, is(switch2));
}
Also used : OpenFlowSwitch(org.onosproject.openflow.controller.OpenFlowSwitch) Test(org.junit.Test)

Aggregations

OpenFlowSwitch (org.onosproject.openflow.controller.OpenFlowSwitch)29 Dpid (org.onosproject.openflow.controller.Dpid)17 OpenFlowController (org.onosproject.openflow.controller.OpenFlowController)5 DeviceId (org.onosproject.net.DeviceId)4 OFPortDesc (org.projectfloodlight.openflow.protocol.OFPortDesc)4 Test (org.junit.Test)3 OpenFlowSwitchListener (org.onosproject.openflow.controller.OpenFlowSwitchListener)3 ArrayList (java.util.ArrayList)2 Type (org.onosproject.net.Device.Type)2 ExtensionTreatmentType (org.onosproject.net.flow.instructions.ExtensionTreatmentType)2 PortDescPropertyType (org.onosproject.openflow.controller.PortDescPropertyType)2 OFFlowLightweightStatsReply (org.projectfloodlight.openflow.protocol.OFFlowLightweightStatsReply)2 OFFlowStatsReply (org.projectfloodlight.openflow.protocol.OFFlowStatsReply)2 OFTableStatsEntry (org.projectfloodlight.openflow.protocol.OFTableStatsEntry)2 OFTableStatsReply (org.projectfloodlight.openflow.protocol.OFTableStatsReply)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