org.onosproject.net.flow.DefaultFlowRule Java Examples

The following examples show how to use org.onosproject.net.flow.DefaultFlowRule. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OpenVSwitchPipeline.java    From onos with Apache License 2.0 6 votes vote down vote up
private Collection<FlowRule> processVersatile(ForwardingObjective fwd) {
    log.debug("Processing versatile forwarding objective");
    TrafficSelector selector = fwd.selector();
    TrafficTreatment tb = fwd.treatment();
    FlowRule.Builder ruleBuilder = DefaultFlowRule.builder().fromApp(fwd.appId()).withPriority(fwd.priority())
            .forDevice(deviceId).withSelector(selector).withTreatment(tb).makeTemporary(TIME_OUT);
    ruleBuilder.withPriority(fwd.priority());
    if (fwd.priority() == 100) {
        ruleBuilder.forTable(ENCAP_OUTPUT_TABLE);
    } else if (fwd.priority() == 200) {
        ruleBuilder.forTable(TUN_SEND_TABLE);
    } else {
        ruleBuilder.forTable(CLASSIFIER_TABLE);
    }

    if (fwd.permanent()) {
        ruleBuilder.makePermanent();
    }
    return Collections.singletonList(ruleBuilder.build());
}
 
Example #2
Source File: OvsCorsaPipeline.java    From onos with Apache License 2.0 6 votes vote down vote up
private void processLocalTable(boolean install) {
    TrafficSelector.Builder selector = DefaultTrafficSelector.builder();

    TrafficTreatment.Builder treatment = DefaultTrafficTreatment
            .builder()
    .punt();

    FlowRule rule = DefaultFlowRule.builder()
            .forDevice(deviceId)
            .withSelector(selector.build())
            .withTreatment(treatment.build())
            .withPriority(CONTROLLER_PRIORITY)
            .fromApp(appId)
            .makePermanent()
            .forTable(LOCAL_TABLE).build();

    processFlowRule(true, rule, "Provisioned Local table");
}
 
Example #3
Source File: FlowEntryBuilder.java    From onos with Apache License 2.0 6 votes vote down vote up
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);
    }
}
 
Example #4
Source File: AbstractHPPipeline.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * HP hardware table initialization.
 * Installs rule goto HP_SOFTWARE_TABLE in HP_HARDWARE_TABLE
 */
private void installHPHardwareTable() {
    TrafficSelector.Builder selector = DefaultTrafficSelector.builder();

    TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
    //treatment.setOutput(PortNumber.NORMAL);
    treatment.transition(HP_SOFTWARE_TABLE);

    FlowRule rule = DefaultFlowRule.builder().forDevice(this.deviceId)
            .withSelector(selector.build())
            .withTreatment(treatment.build())
            .withPriority(0)
            .fromApp(appId)
            .makePermanent()
            .forTable(HP_HARDWARE_TABLE)
            .build();

    this.applyRules(true, rule);
}
 
Example #5
Source File: AbstractHPPipeline.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * HP Table 0 initialization.
 * Installs rule goto HP_HARDWARE_TABLE in HP_TABLE_ZERO
 */
private void installHPTableZero() {
    TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
    TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();

    treatment.transition(HP_HARDWARE_TABLE);

    FlowRule rule = DefaultFlowRule.builder().forDevice(this.deviceId)
            .withSelector(selector.build())
            .withTreatment(treatment.build())
            .withPriority(0)
            .fromApp(appId)
            .makePermanent()
            .forTable(HP_TABLE_ZERO)
            .build();

    this.applyRules(true, rule);
}
 
Example #6
Source File: CorsaPipelineV3.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
protected Builder processVlanFiler(FilteringObjective filt, VlanIdCriterion vlan, PortCriterion port) {
    log.debug("adding rule for VLAN: {}", vlan.vlanId());
    TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
    TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
    selector.matchVlanId(vlan.vlanId());
    selector.matchInPort(port.port());
            /* Static treatment for VLAN_CIRCUIT_TABLE */
    treatment.setVlanPcp(MAX_VLAN_PCP);
    treatment.setQueue(0);
    treatment.meter(MeterId.meterId(defaultMeterId.id())); /* use default meter (Green) */
    treatment.transition(L3_IF_MAC_DA_TABLE);
    return DefaultFlowRule.builder()
            .withSelector(selector.build())
            .withTreatment(treatment.build())
            .withPriority(CONTROLLER_PRIORITY)
            .makePermanent()
            .forTable(VLAN_CIRCUIT_TABLE);
}
 
Example #7
Source File: CorsaPipelineV39.java    From onos with Apache License 2.0 6 votes vote down vote up
private void processRouterPacket(boolean install) {

        deviceService.getPorts(deviceId).forEach(port -> {
            if (!port.number().isLogical()) {
                TrafficSelector.Builder selector = DefaultTrafficSelector.builder()
                        .matchVlanId(VlanId.vlanId(NATIVE_VLAN))
                        .matchInPort(port.number());

                TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder()
                        .setVlanPcp((byte) 0)
                        .setQueue(0)
                        .meter(defaultMeterId)
                        .transition(L3_IF_MAC_DA_TABLE);

                FlowRule rule = DefaultFlowRule.builder()
                        .forDevice(deviceId)
                        .withSelector(selector.build())
                        .withTreatment(treatment.build())
                        .withPriority(CONTROLLER_PRIORITY)
                        .fromApp(appId)
                        .makePermanent()
                        .forTable(VLAN_CIRCUIT_TABLE).build();
                processFlowRule(install, rule, "Provisioned vlan circuit table");
            }
        });
    }
 
Example #8
Source File: K8sFlowRuleManager.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public void setUpTableMissEntry(DeviceId deviceId, int table) {
    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(table)
            .build();

    applyRule(flowRule, true);
}
 
Example #9
Source File: SimpleFabricRouting.java    From onos with Apache License 2.0 6 votes vote down vote up
private FlowRule generateInterceptFlowRule(boolean isDstLocalSubnet, DeviceId deviceId, IpPrefix prefix) {
    TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
    if (prefix.isIp4()) {
        selector.matchEthType(Ethernet.TYPE_IPV4);
        if (prefix.prefixLength() > 0) {
            selector.matchIPDst(prefix);
        }
    } else {
        selector.matchEthType(Ethernet.TYPE_IPV6);
        if (prefix.prefixLength() > 0) {
            selector.matchIPv6Dst(prefix);
        }
    }
    FlowRule rule = DefaultFlowRule.builder()
            .forDevice(deviceId)
            .withPriority(reactivePriority(false, isDstLocalSubnet, prefix.prefixLength()))
            .withSelector(selector.build())
            .withTreatment(DefaultTrafficTreatment.builder().punt().build())
            .fromApp(appId)
            .makePermanent()
            .forTable(0).build();
    return rule;
}
 
Example #10
Source File: CorsaPipelineV3.java    From onos with Apache License 2.0 6 votes vote down vote up
private void processLocalTable(boolean install) {
    int table = LOCAL_TABLE;
    /* Default action */
    processTableMissDrop(install, table, "Provisioned local table drop");

    /* Send all protocols to controller */
    TrafficSelector.Builder selector = DefaultTrafficSelector.builder();

    TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
    treatment.punt();

    FlowRule rule = DefaultFlowRule.builder()
            .forDevice(deviceId)
            .withSelector(selector.build())
            .withTreatment(treatment.build())
            .withPriority(CONTROLLER_PRIORITY)
            .fromApp(appId)
            .makePermanent()
            .forTable(table).build();
    processFlowRule(install, rule, "Provisioned ether type table to controller");
}
 
Example #11
Source File: OplinkPowerConfigUtil.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Replace flow with new flow containing Oplink attenuation extension instruction. Also resets metrics.
 *
 * @param flowEntry flow entry
 * @param power power value
 */
private void addAttenuation(FlowEntry flowEntry, long power) {
    FlowRule.Builder flowBuilder = new DefaultFlowRule.Builder()
            .withCookie(flowEntry.id().value())
            .withPriority(flowEntry.priority())
            .forDevice(flowEntry.deviceId())
            .forTable(flowEntry.tableId());
    if (flowEntry.isPermanent()) {
        flowBuilder.makePermanent();
    } else {
        flowBuilder.makeTemporary(flowEntry.timeout());
    }
    flowBuilder.withSelector(flowEntry.selector());
    // Copy original instructions and add attenuation instruction
    TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder();
    flowEntry.treatment().allInstructions().forEach(ins -> treatmentBuilder.add(ins));
    final DriverHandler handler = behaviour.handler();
    treatmentBuilder.add(Instructions.extension(new OplinkAttenuation((int) power), handler.data().deviceId()));
    flowBuilder.withTreatment(treatmentBuilder.build());

    FlowRuleService service = handler.get(FlowRuleService.class);
    service.applyFlowRules(flowBuilder.build());
}
 
Example #12
Source File: MyTunnelApp.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Inserts a flow rule in the system that using a PI criterion and action.
 *
 * @param switchId    switch ID
 * @param tableId     table ID
 * @param piCriterion PI criterion
 * @param piAction    PI action
 */
private void insertPiFlowRule(DeviceId switchId, PiTableId tableId,
                              PiCriterion piCriterion, PiAction piAction) {
    FlowRule rule = DefaultFlowRule.builder()
            .forDevice(switchId)
            .forTable(tableId)
            .fromApp(appId)
            .withPriority(FLOW_RULE_PRIORITY)
            .makePermanent()
            .withSelector(DefaultTrafficSelector.builder()
                                  .matchPi(piCriterion).build())
            .withTreatment(DefaultTrafficTreatment.builder()
                                   .piTableAction(piAction).build())
            .build();
    flowRuleService.applyFlowRules(rule);
}
 
Example #13
Source File: OvsOfdpaPipeline.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Creates punt table entry that matches IN_PORT and VLAN_VID and forwards
 * packet to controller tagged.
 *
 * @param portNumber port number
 * @param packetVlan vlan tag of the packet
 * @return punt table flow rule
 */
private FlowRule buildPuntTableRuleTagged(PortNumber portNumber, VlanId packetVlan) {
    TrafficSelector.Builder sbuilder = DefaultTrafficSelector.builder()
            .matchInPort(portNumber)
            .matchVlanId(packetVlan);
    TrafficTreatment.Builder tbuilder = DefaultTrafficTreatment.builder().punt();

    return DefaultFlowRule.builder()
            .forDevice(deviceId)
            .withSelector(sbuilder.build())
            .withTreatment(tbuilder.build())
            .withPriority(PacketPriority.CONTROL.priorityValue())
            .fromApp(driverId)
            .makePermanent()
            .forTable(PUNT_TABLE).build();
}
 
Example #14
Source File: OvsCorsaPipeline.java    From onos with Apache License 2.0 6 votes vote down vote up
protected void processVlanMplsTable(boolean install) {
    TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
    TrafficTreatment.Builder treatment = DefaultTrafficTreatment
            .builder();
    FlowRuleOperations.Builder ops = FlowRuleOperations.builder();
    FlowRule rule;

    selector.matchVlanId(VlanId.ANY);
    treatment.transition(VLAN_TABLE);

    rule = DefaultFlowRule.builder()
            .forDevice(deviceId)
            .withSelector(selector.build())
            .withTreatment(treatment.build())
            .withPriority(CONTROLLER_PRIORITY)
            .fromApp(appId)
            .makePermanent()
            .forTable(VLAN_MPLS_TABLE).build();

    processFlowRule(true, rule, "Provisioned vlan/mpls table");
}
 
Example #15
Source File: CorsaPipelineV39.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
protected void processL3IFMacDATable(boolean install) {
    int table = L3_IF_MAC_DA_TABLE;

    //Default action
    processTableMissDrop(install, table, "Provisioned l3 table drop");

    TrafficSelector.Builder selector = DefaultTrafficSelector.builder();

    TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder()
            .transition(ETHER_TABLE);

    FlowRule rule = DefaultFlowRule.builder()
            .forDevice(deviceId)
            .withSelector(selector.build())
            .withTreatment(treatment.build())
            .withPriority(1)
            .fromApp(appId)
            .makePermanent()
            .forTable(table).build();
    processFlowRule(install, rule, "Provisioned l3 table");
}
 
Example #16
Source File: FlowEntryBuilder.java    From onos with Apache License 2.0 6 votes vote down vote up
private FlowEntry createFlowEntryFromLightweightStat() {
    FlowRule.Builder builder = DefaultFlowRule.builder()
            .forDevice(deviceId)
            .withSelector(buildSelector())
            .withPriority(lightWeightStat.getPriority())
            .withIdleTimeout(0)
            .withCookie(0);
    FlowStatParser flowLightweightStatParser = new FlowStatParser(lightWeightStat.getStats());
    builder.forTable(lightWeightStat.getTableId().getValue());
    if (afsc != null && flowLightweightStatParser.isDurationReceived()) {
        FlowEntry.FlowLiveType liveType = afsc.calFlowLiveType(flowLightweightStatParser.getDuration());
        return new DefaultFlowEntry(builder.build(), FlowEntryState.ADDED,
                SECONDS.toNanos(flowLightweightStatParser.getDuration())
                        + flowLightweightStatParser.getDuration(), NANOSECONDS,
                liveType,
                flowLightweightStatParser.getPacketCount(),
                flowLightweightStatParser.getByteCount());
    } else {
        return new DefaultFlowEntry(builder.build(), FlowEntryState.ADDED,
                flowLightweightStatParser.getDuration(),
                flowLightweightStatParser.getPacketCount(),
                flowLightweightStatParser.getByteCount());
    }
}
 
Example #17
Source File: SpringOpenTTP.java    From onos with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #18
Source File: OpenstackFlowRuleManager.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public void setRule(ApplicationId appId,
                    DeviceId deviceId,
                    TrafficSelector selector,
                    TrafficTreatment treatment,
                    int priority,
                    int tableType,
                    boolean install) {

    FlowRule.Builder flowRuleBuilder = DefaultFlowRule.builder()
            .forDevice(deviceId)
            .withSelector(selector)
            .withTreatment(treatment)
            .withPriority(priority)
            .fromApp(appId)
            .forTable(tableType);

    if (priority == Constants.PRIORITY_SNAT_RULE) {
        flowRuleBuilder.makeTemporary(TIMEOUT_SNAT_RULE);
    } else {
        flowRuleBuilder.makePermanent();
    }

    applyRule(flowRuleBuilder.build(), install);
}
 
Example #19
Source File: DefaultVirtualFlowRuleProviderTest.java    From onos with Apache License 2.0 6 votes vote down vote up
@Test
public void removeVirtualizeFlowRule() {
    TrafficSelector ts = DefaultTrafficSelector.builder().build();
    TrafficTreatment tr = DefaultTrafficTreatment.builder()
            .setOutput(PORT_NUM2).build();

    FlowRule r1 = DefaultFlowRule.builder()
            .forDevice(VDID)
            .withSelector(ts)
            .withTreatment(tr)
            .withPriority(10)
            .fromApp(vAppId)
            .makeTemporary(TIMEOUT)
            .build();

    virtualProvider.removeFlowRule(VNET_ID, r1);

    assertEquals("0 rules should exist", 0,
                 virtualProvider.flowRuleService.getFlowRuleCount());
}
 
Example #20
Source File: OpenstackFlowRuleManagerTest.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Tests whether the set rule method installs the flow rules properly.
 */
@Test
public void testSetRule() {
    int testPriority = 10;
    int testTableType = 10;

    fros = Sets.newConcurrentHashSet();

    TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector.builder();
    TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder();

    FlowRule.Builder flowRuleBuilder = DefaultFlowRule.builder()
            .forDevice(DEVICE_ID)
            .withSelector(selectorBuilder.build())
            .withTreatment(treatmentBuilder.build())
            .withPriority(testPriority)
            .fromApp(TEST_APP_ID)
            .forTable(testTableType)
            .makePermanent();

    target.setRule(TEST_APP_ID, DEVICE_ID, selectorBuilder.build(),
            treatmentBuilder.build(), testPriority, testTableType, true);
    validateFlowRule(flowRuleBuilder.build());
}
 
Example #21
Source File: K8sFlowRuleManager.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public void setRule(ApplicationId appId, DeviceId deviceId,
                    TrafficSelector selector, TrafficTreatment treatment,
                    int priority, int tableType, boolean install) {
    FlowRule.Builder flowRuleBuilder = DefaultFlowRule.builder()
            .forDevice(deviceId)
            .withSelector(selector)
            .withTreatment(treatment)
            .withPriority(priority)
            .fromApp(appId)
            .forTable(tableType);

    if (priority == PRIORITY_SNAT_RULE) {
        flowRuleBuilder.makeTemporary(TIMEOUT_SNAT_RULE);
    } else {
        flowRuleBuilder.makePermanent();
    }

    applyRule(flowRuleBuilder.build(), install);
}
 
Example #22
Source File: AbstractCorsaPipeline.java    From onos with Apache License 2.0 6 votes vote down vote up
protected void processTableMissDrop(boolean install, int table, String description) {
    TrafficSelector.Builder selector = DefaultTrafficSelector.builder();

    TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
    treatment.drop();

    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);
}
 
Example #23
Source File: AbstractCorsaPipeline.java    From onos with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #24
Source File: ScaleTestManager.java    From onos with Apache License 2.0 6 votes vote down vote up
private void addMoreFlows(int flowsPerDevice, Device device, DeviceId id,
                          int currentFlowCount) {
    int c = flowsPerDevice - currentFlowCount;
    log.info("Adding {} flows for device {}", c, id);
    List<PortNumber> ports = devicePorts(device);
    FlowRuleOperations.Builder ops = FlowRuleOperations.builder();
    for (int i = 0; i < c; i++) {
        FlowRule.Builder frb = DefaultFlowRule.builder();
        frb.fromApp(appId).makePermanent().withPriority((currentFlowCount + i) % FlowRule.MAX_PRIORITY);
        TrafficSelector.Builder tsb = DefaultTrafficSelector.builder();
        TrafficTreatment.Builder ttb = DefaultTrafficTreatment.builder();

        tsb.matchEthType(Ethernet.TYPE_IPV4);
        tsb.matchEthDst(randomMac());
        ttb.setEthDst(randomMac()).setEthSrc(randomMac());
        ttb.setOutput(randomPort(ports));
        frb.withSelector(tsb.build()).withTreatment(ttb.build());
        ops.add(frb.forDevice(id).build());
    }
    flowRuleService.apply(ops.build());
}
 
Example #25
Source File: PointToPointIntentCompiler.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Manufactures flow rule with treatment that is defined by failover
 * group and traffic selector determined by ingress port of the intent.
 *
 * @param intent intent which is being compiled (for appId)
 * @return       a list of a singular flow rule with fast failover
 *               outport traffic treatment
 */
private List<FlowRule> createFailoverFlowRules(PointToPointIntent intent) {
    List<FlowRule> flowRules = new ArrayList<>();

    ConnectPoint ingress = intent.filteredIngressPoint().connectPoint();
    DeviceId deviceId = ingress.deviceId();

    // flow rule with failover traffic treatment
    TrafficSelector trafficSelector = DefaultTrafficSelector.builder(intent.selector())
                                                  .matchInPort(ingress.port()).build();

    FlowRule.Builder flowRuleBuilder = DefaultFlowRule.builder();
    flowRules.add(flowRuleBuilder.withSelector(trafficSelector)
                          .withTreatment(buildFailoverTreatment(deviceId, makeGroupKey(intent.id())))
                          .fromApp(intent.appId())
                          .makePermanent()
                          .forDevice(deviceId)
                          .withPriority(PRIORITY)
                          .build());

    return flowRules;
}
 
Example #26
Source File: OvsOfdpaPipeline.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
protected List<List<FlowRule>> processEthDstOnlyFilter(EthCriterion ethCriterion,
                                                 ApplicationId applicationId) {
    TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
    TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();
    selector.matchEthType(Ethernet.TYPE_IPV4);
    selector.matchEthDst(ethCriterion.mac());
    treatment.transition(UNICAST_ROUTING_TABLE);
    FlowRule rule = DefaultFlowRule.builder()
            .forDevice(deviceId)
            .withSelector(selector.build())
            .withTreatment(treatment.build())
            .withPriority(DEFAULT_PRIORITY)
            .fromApp(applicationId)
            .makePermanent()
            .forTable(TMAC_TABLE).build();
    return ImmutableList.of(ImmutableList.of(rule));
}
 
Example #27
Source File: OltPipeline.java    From onos with Apache License 2.0 5 votes vote down vote up
private void installNoModificationRules(ForwardingObjective fwd) {
    Instructions.OutputInstruction output = (Instructions.OutputInstruction) fetchOutput(fwd, DOWNSTREAM);
    Instructions.MetadataInstruction writeMetadata = fetchWriteMetadata(fwd);
    Instructions.MeterInstruction meter = (Instructions.MeterInstruction) fetchMeter(fwd);

    TrafficSelector selector = fwd.selector();

    Criterion inport = selector.getCriterion(Criterion.Type.IN_PORT);
    Criterion outerVlan = selector.getCriterion(Criterion.Type.VLAN_VID);
    Criterion innerVlan = selector.getCriterion(Criterion.Type.INNER_VLAN_VID);

    if (inport == null || output == null || innerVlan == null || outerVlan == null) {
        log.error("Forwarding objective is underspecified: {}", fwd);
        fail(fwd, ObjectiveError.BADPARAMS);
        return;
    }


    FlowRule.Builder outer = DefaultFlowRule.builder()
            .fromApp(fwd.appId())
            .forDevice(deviceId)
            .makePermanent()
            .withPriority(fwd.priority())
            .withSelector(buildSelector(inport, outerVlan))
            .withTreatment(buildTreatment(output, writeMetadata, meter));

    applyRules(fwd, outer);
}
 
Example #28
Source File: OpenVSwitchPipeline.java    From onos with Apache License 2.0 5 votes vote down vote up
private void processMacTable(boolean install) {
    TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
    TrafficTreatment.Builder treatment = DefaultTrafficTreatment.builder();

    treatment.drop();

    FlowRule rule;
    rule = DefaultFlowRule.builder().forDevice(deviceId)
            .withSelector(selector.build())
            .withTreatment(treatment.build())
            .withPriority(TABLE_MISS_PRIORITY).fromApp(appId)
            .makePermanent().forTable(MAC_TABLE).build();

    applyRules(install, rule);
}
 
Example #29
Source File: DefaultVirtualFlowRuleProvider.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Generate physical rules when a virtual flow rule can be handled inside
 * a single physical switch.
 *
 * @param networkId The virtual network identifier
 * @param ingressPoint The ingress point of the physical network
 * @param egressPoint The egress point of the physical network
 * @param commonSelector A common traffic selector between the virtual
 *                       and physical flow rules
 * @param commonTreatment A common traffic treatment between the virtual
 *                        and physical flow rules
 * @param flowRule The virtual flow rule to be translated
 * @return A set of flow rules for the physical network
 */
private Set<FlowRule> generateRuleForSingle(NetworkId networkId,
        ConnectPoint ingressPoint,
        ConnectPoint egressPoint,
        TrafficSelector commonSelector,
        TrafficTreatment commonTreatment,
        FlowRule flowRule) {

    Set<FlowRule> outRules = new HashSet<>();

    TrafficSelector.Builder selectorBuilder = DefaultTrafficSelector
            .builder(commonSelector)
            .matchInPort(ingressPoint.port());

    TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment
            .builder(commonTreatment)
            .setOutput(egressPoint.port());

    FlowRule.Builder ruleBuilder = DefaultFlowRule.builder()
            .fromApp(vnService.getVirtualNetworkApplicationId(networkId))
            .forDevice(ingressPoint.deviceId())
            .withSelector(selectorBuilder.build())
            .withTreatment(treatmentBuilder.build())
            .withIdleTimeout(flowRule.timeout())
            .withPriority(flowRule.priority());

    FlowRule rule = ruleBuilder.build();
    frm.addIngressRule(flowRule, rule, networkId);
    outRules.add(rule);

    return outRules;
}
 
Example #30
Source File: FabricForwardingPipelineTest.java    From onos with Apache License 2.0 5 votes vote down vote up
private void testSpecificForward(PiTableId expectedTableId, TrafficSelector expectedSelector,
                                 TrafficSelector selector, Integer nextId, TrafficTreatment treatment)
        throws FabricPipelinerException {
    ForwardingObjective.Builder fwd = DefaultForwardingObjective.builder()
            .withSelector(selector)
            .withPriority(PRIORITY)
            .fromApp(APP_ID)
            .makePermanent()
            .withTreatment(treatment)
            .withFlag(ForwardingObjective.Flag.SPECIFIC);

    if (nextId != null) {
        fwd.nextStep(nextId);
    }

    ObjectiveTranslation actualTranslation = translator.translate(fwd.add());

    FlowRule expectedFlowRule = DefaultFlowRule.builder()
            .forDevice(DEVICE_ID)
            .forTable(expectedTableId)
            .withPriority(PRIORITY)
            .makePermanent()
            .withSelector(expectedSelector)
            .withTreatment(treatment)
            .fromApp(APP_ID)
            .build();

    ObjectiveTranslation expectedTranslation = ObjectiveTranslation.builder()
            .addFlowRule(expectedFlowRule)
            .build();

    assertEquals(expectedTranslation, actualTranslation);
}