blob: 4f356cfff36eeaf1e28a9525c71b3d74e97343a0 [file] [log] [blame]
pier7afc7522019-05-10 13:19:15 +02001/*
2 * Copyright 2019-present Open Networking Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package org.onosproject.driver.pipeline.ofdpa;
18
19import com.google.common.collect.Lists;
20import org.junit.Before;
21import org.junit.Test;
22import org.onlab.packet.Ethernet;
23import org.onlab.packet.IpPrefix;
24import org.onosproject.core.ApplicationId;
25import org.onosproject.core.DefaultApplicationId;
26import org.onosproject.net.DeviceId;
27import org.onosproject.net.NetTestTools;
28import org.onosproject.net.flow.DefaultTrafficSelector;
29import org.onosproject.net.flow.DefaultTrafficTreatment;
30import org.onosproject.net.flow.FlowRuleOperations;
31import org.onosproject.net.flow.FlowRuleServiceAdapter;
32import org.onosproject.net.flow.TrafficSelector;
33import org.onosproject.net.flow.TrafficTreatment;
34import org.onosproject.net.flowobjective.DefaultForwardingObjective;
35import org.onosproject.net.flowobjective.ForwardingObjective;
36
37import java.util.List;
38
39import static org.easymock.EasyMock.*;
40import static org.junit.Assert.assertEquals;
41import static org.onlab.junit.TestTools.assertAfter;
42
43/**
44 * Tests for Broadcom's OF-DPA v2.0 TTP.
45 */
46public class Ofdpa2PipelineTest {
47
48 // Pipeliner and accumulator parameters
49 private Ofdpa2Pipeline ofdpa2Pipeline;
50 private static final int MAX_FWD = 2;
51 private static final int MAX_BATCH = 1000;
52 private static final int MAX_IDLE = 1000;
53 private static final int WAIT_TIME = 50;
54 // Forwarding objectives to be tested
55 private static final int PRIORITY = 1000;
56 private static final ApplicationId APP_ID = new DefaultApplicationId(1, "org.onosproject.test");
57 private ForwardingObjective versatileFwd = DefaultForwardingObjective.builder()
58 .fromApp(APP_ID)
59 .withSelector(NetTestTools.emptySelector())
60 .withTreatment(NetTestTools.emptyTreatment())
61 .withPriority(PRIORITY)
62 .withFlag(ForwardingObjective.Flag.VERSATILE)
63 .add();
64 private static final TrafficSelector IP_SELECTOR = DefaultTrafficSelector.builder()
65 .matchEthType(Ethernet.TYPE_IPV4)
66 .matchIPDst(IpPrefix.valueOf("10.0.0.0/24"))
67 .build();
68 private static final TrafficTreatment CTRL_TREATMENT = DefaultTrafficTreatment.builder()
69 .punt()
70 .build();
71 private ForwardingObjective specificFwd = DefaultForwardingObjective
72 .builder()
73 .fromApp(APP_ID)
74 .withSelector(IP_SELECTOR)
75 .withTreatment(CTRL_TREATMENT)
76 .withPriority(PRIORITY)
77 .withFlag(ForwardingObjective.Flag.SPECIFIC)
78 .add();
79 private static final DeviceId DEV1 = DeviceId.deviceId("of:1");
80 // Test flow rule service
81 private TestFlowRuleService testFlowRuleService;
82
83 @Before
84 public void setUp() {
85 ofdpa2Pipeline = new Ofdpa2Pipeline();
86 ofdpa2Pipeline.setupAccumulatorForTests(MAX_FWD,
87 MAX_BATCH,
88 MAX_IDLE);
89 ofdpa2Pipeline.deviceId = DEV1;
90 testFlowRuleService = new TestFlowRuleService();
91 ofdpa2Pipeline.flowRuleService = testFlowRuleService;
92 }
93
94 @Test
95 public void verifyAccumulation() {
96 // Versatile are not accumulated
97 ofdpa2Pipeline.forward(versatileFwd);
98 assertAfter(WAIT_TIME, WAIT_TIME * 2, () -> assertEquals(1, testFlowRuleService.fops.size()));
99 // Specific are delayed for MAX_IDLE
100 ofdpa2Pipeline.forward(specificFwd);
101 assertAfter(WAIT_TIME, WAIT_TIME * 2, () -> assertEquals(1, testFlowRuleService.fops.size()));
102 assertAfter(WAIT_TIME, MAX_IDLE + WAIT_TIME, () -> assertEquals(2, testFlowRuleService.fops.size()));
103 }
104
105 // Simplified version of the FlowRuleService
106 private class TestFlowRuleService extends FlowRuleServiceAdapter {
107
108 List<FlowRuleOperations> fops = Lists.newArrayList();
109
110 @Override
111 public void apply(FlowRuleOperations ops) {
112 fops.add(ops);
113 }
114
115 }
116
117}