本文整理汇总了Java中org.onosproject.net.flow.FlowRule类的典型用法代码示例。如果您正苦于以下问题:Java FlowRule类的具体用法?Java FlowRule怎么用?Java FlowRule使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FlowRule类属于org.onosproject.net.flow包,在下文中一共展示了FlowRule类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createFlows
import org.onosproject.net.flow.FlowRule; //导入依赖的package包/类
/**
* Creates new flow rules. Creates and installs a new flow rules.<br>
* Instructions description:
* https://wiki.onosproject.org/display/ONOS/Flow+Rule+Instructions
* <br>
* Criteria description:
* https://wiki.onosproject.org/display/ONOS/Flow+Rule+Criteria
*
* @param stream flow rules JSON
* @return status of the request - CREATED if the JSON is correct,
* BAD_REQUEST if the JSON is invalid
* @onos.rsModel FlowsBatchPost
*/
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response createFlows(@QueryParam("appId") String appId, InputStream stream) {
try {
ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
ArrayNode flowsArray = (ArrayNode) jsonTree.get(FLOWS);
if (appId != null) {
flowsArray.forEach(flowJson -> ((ObjectNode) flowJson).put("appId", appId));
}
List<FlowRule> rules = codec(FlowRule.class).decode(flowsArray, this);
service.applyFlowRules(rules.toArray(new FlowRule[rules.size()]));
rules.forEach(flowRule -> {
ObjectNode flowNode = mapper().createObjectNode();
flowNode.put(DEVICE_ID, flowRule.deviceId().toString())
.put(FLOW_ID, flowRule.id().value());
flowsNode.add(flowNode);
});
} catch (IOException ex) {
throw new IllegalArgumentException(ex);
}
return Response.ok(root).build();
}
示例2: testFlowRuleBatchEntry
import org.onosproject.net.flow.FlowRule; //导入依赖的package包/类
@Test
public void testFlowRuleBatchEntry() {
final FlowRule rule1 =
DefaultFlowRule.builder()
.forDevice(DID1)
.withSelector(DefaultTrafficSelector.emptySelector())
.withTreatment(DefaultTrafficTreatment.emptyTreatment())
.withPriority(0)
.fromApp(new DefaultApplicationId(1, "1"))
.makeTemporary(1)
.build();
final FlowRuleBatchEntry entry1 =
new FlowRuleBatchEntry(FlowRuleBatchEntry.FlowRuleOperation.ADD, rule1);
final FlowRuleBatchEntry entry2 =
new FlowRuleBatchEntry(FlowRuleBatchEntry.FlowRuleOperation.ADD, rule1, 100L);
testSerializedEquals(entry1);
testSerializedEquals(entry2);
}
示例3: highestHitter
import org.onosproject.net.flow.FlowRule; //导入依赖的package包/类
@Override
public FlowRule highestHitter(ConnectPoint connectPoint) {
checkPermission(STATISTIC_READ);
Set<FlowEntry> hitters = statisticStore.getCurrentStatistic(connectPoint);
if (hitters.isEmpty()) {
return null;
}
FlowEntry max = hitters.iterator().next();
for (FlowEntry entry : hitters) {
if (entry.bytes() > max.bytes()) {
max = entry;
}
}
return max;
}
示例4: removeFromStatistics
import org.onosproject.net.flow.FlowRule; //导入依赖的package包/类
@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);
}
}
示例5: processForward
import org.onosproject.net.flow.FlowRule; //导入依赖的package包/类
private Collection<FlowRule> processForward(ForwardingObjective fwd) {
log.debug("Processing forwarding object");
FlowRule.Builder ruleBuilder = DefaultFlowRule.builder()
.forDevice(deviceId)
.withSelector(fwd.selector())
.withTreatment(fwd.treatment())
.withPriority(fwd.priority())
.fromApp(fwd.appId())
.forTable(SOFTWARE_TABLE_START);
if (fwd.permanent()) {
ruleBuilder.makePermanent();
} else {
ruleBuilder.makeTemporary(TIME_OUT);
}
return Collections.singletonList(ruleBuilder.build());
}
示例6: processForwardingTable
import org.onosproject.net.flow.FlowRule; //导入依赖的package包/类
private void processForwardingTable(boolean install) {
TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
treatment.drop();
FlowRule flowRule = DefaultFlowRule.builder()
.forDevice(deviceId)
.withSelector(selector.build())
.withTreatment(treatment.build())
.withPriority(DROP_PRIORITY)
.fromApp(appId)
.makePermanent()
.forTable(FORWARDING_TABLE)
.build();
applyRules(install, flowRule);
}
示例7: flowMetrics
import org.onosproject.net.flow.FlowRule; //导入依赖的package包/类
@Test
public void flowMetrics() {
FlowRule f1 = flowRule(1, 1);
FlowRule f2 = flowRule(2, 2);
FlowRule f3 = flowRule(3, 3);
mgr.applyFlowRules(f1, f2, f3);
FlowEntry fe1 = new DefaultFlowEntry(f1);
FlowEntry fe2 = new DefaultFlowEntry(f2);
//FlowRule updatedF1 = flowRule(f1, FlowRuleState.ADDED);
//FlowRule updatedF2 = flowRule(f2, FlowRuleState.ADDED);
providerService.pushFlowMetrics(DID, Lists.newArrayList(fe1, fe2));
assertTrue("Entries should be added.",
validateState(ImmutableMap.of(
f1, FlowEntryState.ADDED,
f2, FlowEntryState.ADDED,
f3, FlowEntryState.PENDING_ADD)));
validateEvents(RULE_ADD_REQUESTED, RULE_ADD_REQUESTED, RULE_ADD_REQUESTED,
RULE_ADDED, RULE_ADDED);
}
示例8: processEthDstOnlyFilter
import org.onosproject.net.flow.FlowRule; //导入依赖的package包/类
protected List<FlowRule> processEthDstOnlyFilter(EthCriterion ethCriterion,
ApplicationId applicationId, int priority) {
TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
selector.matchEthType(Ethernet.TYPE_IPV4);
selector.matchEthDst(ethCriterion.mac());
treatment.transition(TABLE_IPV4_UNICAST);
FlowRule rule = DefaultFlowRule.builder()
.forDevice(deviceId)
.withSelector(selector.build())
.withTreatment(treatment.build())
.withPriority(priority)
.fromApp(applicationId)
.makePermanent()
.forTable(TABLE_TMAC).build();
return ImmutableList.<FlowRule>builder().add(rule).build();
}
示例9: populateTableMissEntry
import org.onosproject.net.flow.FlowRule; //导入依赖的package包/类
protected void populateTableMissEntry(int tableToAdd,
boolean toControllerNow,
boolean toControllerWrite,
boolean toTable, int tableToSend) {
TrafficSelector selector = DefaultTrafficSelector.builder().build();
TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder();
if (toControllerNow) {
tBuilder.setOutput(PortNumber.CONTROLLER);
}
if (toControllerWrite) {
tBuilder.deferred().setOutput(PortNumber.CONTROLLER);
}
if (toTable) {
tBuilder.transition(tableToSend);
}
FlowRule flow = DefaultFlowRule.builder().forDevice(deviceId)
.withSelector(selector).withTreatment(tBuilder.build())
.withPriority(0).fromApp(appId).makePermanent()
.forTable(tableToAdd).build();
flowRuleService.applyFlowRules(flow);
}
示例10: removeFlowStatistic
import org.onosproject.net.flow.FlowRule; //导入依赖的package包/类
@Override
public synchronized void removeFlowStatistic(FlowRule rule) {
ConnectPoint cp = buildConnectPoint(rule);
if (cp == null) {
return;
}
// remove this rule if present from current map
current.computeIfPresent(cp, (c, e) -> {
e.remove(rule);
return e;
});
// remove this on if present from previous map
previous.computeIfPresent(cp, (c, e) -> {
e.remove(rule);
return e;
});
}
示例11: executeBatch
import org.onosproject.net.flow.FlowRule; //导入依赖的package包/类
@Override
public void executeBatch(FlowRuleBatchOperation batch) {
ImmutableList.Builder<FlowRule> toAdd = ImmutableList.builder();
ImmutableList.Builder<FlowRule> toRemove = ImmutableList.builder();
for (FlowRuleBatchEntry fbe : batch.getOperations()) {
if (fbe.operator() == ADD || fbe.operator() == MODIFY) {
toAdd.add(fbe.target());
} else if (fbe.operator() == REMOVE) {
toRemove.add(fbe.target());
}
}
ImmutableList<FlowRule> rulesToAdd = toAdd.build();
ImmutableList<FlowRule> rulesToRemove = toRemove.build();
Collection<FlowRule> added = applyFlowRules(batch.deviceId(), rulesToAdd);
Collection<FlowRule> removed = removeFlowRules(batch.deviceId(), rulesToRemove);
Set<FlowRule> failedRules = Sets.union(Sets.difference(copyOf(rulesToAdd), copyOf(added)),
Sets.difference(copyOf(rulesToRemove), copyOf(removed)));
CompletedBatchOperation status =
new CompletedBatchOperation(failedRules.isEmpty(), failedRules, batch.deviceId());
providerService.batchOperationCompleted(batch.id(), status);
}
示例12: applyFlowRules
import org.onosproject.net.flow.FlowRule; //导入依赖的package包/类
@Test
public void applyFlowRules() {
FlowRule r1 = flowRule(1, 1);
FlowRule r2 = flowRule(2, 2);
FlowRule r3 = flowRule(3, 3);
assertTrue("store should be empty",
Sets.newHashSet(service.getFlowEntries(DID)).isEmpty());
mgr.applyFlowRules(r1, r2, r3);
assertEquals("3 rules should exist", 3, flowCount());
assertTrue("Entries should be pending add.",
validateState(ImmutableMap.of(
r1, FlowEntryState.PENDING_ADD,
r2, FlowEntryState.PENDING_ADD,
r3, FlowEntryState.PENDING_ADD)));
}
示例13: createFlowRule
import org.onosproject.net.flow.FlowRule; //导入依赖的package包/类
private FlowRuleIntent createFlowRule(OpticalCircuitIntent higherIntent,
OpticalConnectivityIntent lowerIntent, Set<TributarySlot> slots) {
// Create optical circuit intent
List<FlowRule> rules = new LinkedList<>();
// at the source: ODUCLT port mapping to OCH port
rules.add(connectPorts(higherIntent.getSrc(), lowerIntent.getSrc(), higherIntent.priority(), slots));
// at the destination: OCH port mapping to ODUCLT port
rules.add(connectPorts(lowerIntent.getDst(), higherIntent.getDst(), higherIntent.priority(), slots));
// Create flow rules for reverse path
if (higherIntent.isBidirectional()) {
// at the destination: OCH port mapping to ODUCLT port
rules.add(connectPorts(lowerIntent.getSrc(), higherIntent.getSrc(), higherIntent.priority(), slots));
// at the source: ODUCLT port mapping to OCH port
rules.add(connectPorts(higherIntent.getDst(), lowerIntent.getDst(), higherIntent.priority(), slots));
}
return new FlowRuleIntent(appId, rules, higherIntent.resources());
}
示例14: processTableMissGoTo
import org.onosproject.net.flow.FlowRule; //导入依赖的package包/类
protected void processTableMissGoTo(boolean install, int table, int goTo, String description) {
TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
treatment.transition(goTo);
FlowRule rule = DefaultFlowRule.builder()
.forDevice(deviceId)
.withSelector(selector.build())
.withTreatment(treatment.build())
.withPriority(DROP_PRIORITY)
.fromApp(appId)
.makePermanent()
.forTable(table).build();
processFlowRule(install, rule, description);
}
示例15: cleanAllFlowRules
import org.onosproject.net.flow.FlowRule; //导入依赖的package包/类
private void cleanAllFlowRules() {
Iterable<Device> deviceList = deviceService.getAvailableDevices();
for (Device d : deviceList) {
DeviceId id = d.id();
log.trace("Searching for flow rules to remove from: " + id);
for (FlowEntry r : flowRuleService.getFlowEntries(id)) {
boolean match = false;
for (Instruction i : r.treatment().allInstructions()) {
if (i.type() == Instruction.Type.OUTPUT) {
OutputInstruction oi = (OutputInstruction) i;
// if the flow has matching src and dst
for (Criterion cr : r.selector().criteria()) {
if (cr.type() == Criterion.Type.ETH_DST || cr.type() == Criterion.Type.ETH_SRC) {
match = true;
}
}
}
}
if (match) {
log.trace("Removed flow rule from device: " + id);
flowRuleService.removeFlowRules((FlowRule) r);
}
}
}
}