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;
}
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();
}
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());
}
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));
}
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));
}
Aggregations