use of org.onosproject.net.flow.FlowEntry in project onos by opennetworkinglab.
the class ECFlowRuleStoreTest method testPurgeFlow.
/**
* Tests purge flow for a device.
*/
@Test
public void testPurgeFlow() {
FlowEntry flowEntry = new DefaultFlowEntry(flowRule);
flowStoreImpl.addOrUpdateFlowRule(flowEntry);
FlowEntry flowEntry1 = new DefaultFlowEntry(flowRule1);
flowStoreImpl.addOrUpdateFlowRule(flowEntry1);
assertFlowsOnDevice(deviceId, 2);
flowStoreImpl.purgeFlowRule(deviceId);
assertFlowsOnDevice(deviceId, 0);
}
use of org.onosproject.net.flow.FlowEntry in project onos by opennetworkinglab.
the class DistributedStatisticStore method removeFromStatistics.
@Override
public synchronized void removeFromStatistics(FlowRule rule) {
ConnectPoint cp = buildConnectPoint(rule);
if (cp == null) {
return;
}
InternalStatisticRepresentation rep = representations.get(cp);
if (rep != null && rep.remove(rule)) {
updatePublishedStats(cp, Collections.emptySet());
}
Set<FlowEntry> values = current.get(cp);
if (values != null) {
values.remove(rule);
}
values = previous.get(cp);
if (values != null) {
values.remove(rule);
}
}
use of org.onosproject.net.flow.FlowEntry in project onos by opennetworkinglab.
the class FlowRuleJuniperImpl method getFlowEntries.
@Override
public Collection<FlowEntry> getFlowEntries() {
DeviceId devId = checkNotNull(this.data().deviceId());
NetconfSession session = lookupNetconfSession(devId);
if (session == null) {
return Collections.emptyList();
}
// Installed static routes
String reply;
try {
reply = session.get(routingTableBuilder());
} catch (NetconfException e) {
throw new IllegalStateException(new NetconfException("Failed to retrieve configuration.", e));
}
Collection<StaticRoute> devicesStaticRoutes = JuniperUtils.parseRoutingTable(loadXmlString(reply));
// Expected FlowEntries installed
FlowRuleService flowRuleService = this.handler().get(FlowRuleService.class);
Iterable<FlowEntry> flowEntries = flowRuleService.getFlowEntries(devId);
Collection<FlowEntry> installedRules = new HashSet<>();
flowEntries.forEach(flowEntry -> {
Optional<IPCriterion> ipCriterion = getIpCriterion(flowEntry);
if (!ipCriterion.isPresent()) {
return;
}
Optional<OutputInstruction> output = getOutput(flowEntry);
if (!output.isPresent()) {
return;
}
// convert FlowRule into static route
getStaticRoute(devId, ipCriterion.get(), output.get(), flowEntry.priority()).ifPresent(staticRoute -> {
if (staticRoute.isLocalRoute()) {
// if the FlowRule is in PENDING_REMOVE or REMOVED, it is not reported.
if (flowEntry.state() == PENDING_REMOVE || flowEntry.state() == REMOVED) {
devicesStaticRoutes.remove(staticRoute);
} else {
// FlowRule is reported installed
installedRules.add(flowEntry);
devicesStaticRoutes.remove(staticRoute);
}
} else {
// if the route is found in the device, the FlowRule is reported installed.
if (devicesStaticRoutes.contains(staticRoute)) {
installedRules.add(flowEntry);
devicesStaticRoutes.remove(staticRoute);
}
}
});
});
if (!devicesStaticRoutes.isEmpty()) {
log.info("Found static routes on device {} not installed by ONOS: {}", devId, devicesStaticRoutes);
// FIXME: enable configuration to purge already installed flows.
// It cannot be allowed by default because it may remove needed management routes
// log.warn("Removing from device {} the FlowEntries not expected {}", deviceId, devicesStaticRoutes);
// devicesStaticRoutes.forEach(staticRoute -> editRoute(session, REMOVE, staticRoute));
}
return installedRules;
}
use of org.onosproject.net.flow.FlowEntry in project onos by opennetworkinglab.
the class LumentumSdnRoadmFlowRuleProgrammable method getFlowEntries.
@Override
public Collection<FlowEntry> getFlowEntries() {
try {
snmp = new LumentumSnmpDevice(handler().data().deviceId());
} catch (IOException e) {
log.error("Failed to connect to device: ", e);
return Collections.emptyList();
}
// Line in is last but one port, line out is last
DeviceService deviceService = this.handler().get(DeviceService.class);
List<Port> ports = deviceService.getPorts(data().deviceId());
if (ports.size() < 2) {
return Collections.emptyList();
}
PortNumber lineIn = ports.get(ports.size() - 2).number();
PortNumber lineOut = ports.get(ports.size() - 1).number();
Collection<FlowEntry> entries = Lists.newLinkedList();
// Add rules
OID addOid = new OID(CTRL_CHANNEL_STATE + "1");
entries.addAll(fetchRules(addOid, true, lineOut).stream().map(fr -> new DefaultFlowEntry(fr, FlowEntry.FlowEntryState.ADDED, 0, 0, 0)).collect(Collectors.toList()));
// Drop rules
OID dropOid = new OID(CTRL_CHANNEL_STATE + "2");
entries.addAll(fetchRules(dropOid, false, lineIn).stream().map(fr -> new DefaultFlowEntry(fr, FlowEntry.FlowEntryState.ADDED, 0, 0, 0)).collect(Collectors.toList()));
return entries;
}
use of org.onosproject.net.flow.FlowEntry in project onos by opennetworkinglab.
the class FlowEntryBuilder method createFlowEntryForFlowMod.
private FlowEntry createFlowEntryForFlowMod(FlowEntryState... state) {
FlowEntryState flowState = state.length > 0 ? state[0] : FlowEntryState.FAILED;
FlowRule.Builder builder = DefaultFlowRule.builder().forDevice(deviceId).withSelector(buildSelector()).withTreatment(buildTreatment()).withPriority(flowMod.getPriority()).withIdleTimeout(flowMod.getIdleTimeout()).withCookie(flowMod.getCookie().getValue());
if (flowMod.getVersion() != OFVersion.OF_10) {
builder.forTable(flowMod.getTableId().getValue());
}
if (afsc != null) {
FlowEntry.FlowLiveType liveType = FlowEntry.FlowLiveType.IMMEDIATE;
return new DefaultFlowEntry(builder.build(), flowState, 0, liveType, 0, 0);
} else {
return new DefaultFlowEntry(builder.build(), flowState, 0, 0, 0);
}
}
Aggregations