use of org.onosproject.openflow.controller.Dpid in project onos by opennetworkinglab.
the class OpenFlowRuleProvider method applyRule.
private void applyRule(FlowRule flowRule) {
Dpid dpid = Dpid.dpid(flowRule.deviceId().uri());
OpenFlowSwitch sw = controller.getSwitch(dpid);
if (sw == null) {
return;
}
sw.sendMsg(FlowModBuilder.builder(flowRule, sw.factory(), Optional.empty(), Optional.of(driverService)).buildFlowAdd());
recordEvent(dpid);
}
use of org.onosproject.openflow.controller.Dpid in project onos by opennetworkinglab.
the class OpenFlowRuleProvider method executeBatch.
@Override
public void executeBatch(FlowRuleBatchOperation batch) {
checkNotNull(batch);
Dpid dpid = Dpid.dpid(batch.deviceId().uri());
OpenFlowSwitch sw = controller.getSwitch(dpid);
// If switch no longer exists, simply return.
if (sw == null) {
Set<FlowRule> failures = ImmutableSet.copyOf(Lists.transform(batch.getOperations(), e -> e.target()));
providerService.batchOperationCompleted(batch.id(), new CompletedBatchOperation(false, failures, batch.deviceId()));
return;
}
pendingBatches.put(batch.id(), new InternalCacheEntry(batch));
// Build a batch of flow mods - to reduce the number i/o asked to the SO
Set<OFFlowMod> mods = Sets.newHashSet();
OFFlowMod mod;
for (FlowRuleBatchEntry fbe : batch.getOperations()) {
FlowModBuilder builder = FlowModBuilder.builder(fbe.target(), sw.factory(), Optional.of(batch.id()), Optional.of(driverService));
switch(fbe.operator()) {
case ADD:
mod = builder.buildFlowAdd();
break;
case REMOVE:
mod = builder.buildFlowDel();
break;
case MODIFY:
mod = builder.buildFlowMod();
break;
default:
log.error("Unsupported batch operation {}; skipping flowmod {}", fbe.operator(), fbe);
continue;
}
mods.add(mod);
}
// Build a list to mantain the order
List<OFMessage> modsTosend = Lists.newArrayList(mods);
OFBarrierRequest.Builder builder = sw.factory().buildBarrierRequest().setXid(batch.id());
// Adds finally the barrier request
modsTosend.add(builder.build());
sw.sendMsg(modsTosend);
// Take into account also the barrier request
recordEvents(dpid, (batch.getOperations().size() + 1));
}
use of org.onosproject.openflow.controller.Dpid in project onos by opennetworkinglab.
the class OpenFlowDeviceProvider method changePortState.
@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()));
}
use of org.onosproject.openflow.controller.Dpid in project onos by opennetworkinglab.
the class OpenFlowDeviceProvider method triggerDisconnect.
@Override
public void triggerDisconnect(DeviceId deviceId) {
Dpid dpid = dpid(deviceId.uri());
OpenFlowSwitch sw = controller.getSwitch(dpid);
if (sw != null) {
LOG.debug("Forcing disconnect for device {}", deviceId);
// TODO: Further consolidate clean-up on device disconnect
listener.switchRemoved(dpid);
sw.disconnectSwitch();
}
}
use of org.onosproject.openflow.controller.Dpid in project onos by opennetworkinglab.
the class OpenFlowGroupProvider method performGroupOperation.
@Override
public void performGroupOperation(DeviceId deviceId, GroupOperations groupOps) {
final Dpid dpid = Dpid.dpid(deviceId.uri());
OpenFlowSwitch sw = controller.getSwitch(dpid);
for (GroupOperation groupOperation : groupOps.operations()) {
if (sw == null) {
log.error("SW {} is not found", dpid);
return;
}
switch(groupOperation.groupType()) {
case SELECT:
case INDIRECT:
case ALL:
case FAILOVER:
break;
case CLONE:
default:
log.warn("Group type {} not supported, ignoring operation [{}]", groupOperation.groupType(), groupOperation);
// Next groupOperation.
continue;
}
final Long groupModXid = XID_COUNTER.getAndIncrement();
GroupModBuilder builder = null;
if (driverService == null) {
builder = GroupModBuilder.builder(groupOperation.buckets(), groupOperation.groupId(), groupOperation.groupType(), sw.factory(), Optional.of(groupModXid));
} else {
builder = GroupModBuilder.builder(groupOperation.buckets(), groupOperation.groupId(), groupOperation.groupType(), sw.factory(), Optional.of(groupModXid), Optional.of(driverService));
}
OFGroupMod groupMod = null;
switch(groupOperation.opType()) {
case ADD:
groupMod = builder.buildGroupAdd();
break;
case MODIFY:
groupMod = builder.buildGroupMod();
break;
case DELETE:
groupMod = builder.buildGroupDel();
break;
default:
log.error("Unsupported Group operation");
return;
}
sw.sendMsg(groupMod);
GroupId groudId = new GroupId(groupMod.getGroup().getGroupNumber());
pendingGroupOperations.put(groudId, groupOperation);
pendingXidMaps.put(groudId, groupModXid);
}
}
Aggregations