Ray Milkey | 97f8f10 | 2014-11-14 14:18:23 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Laboratory |
Ray Milkey | 97f8f10 | 2014-11-14 14:18:23 -0800 | [diff] [blame] | 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 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.net.flow; |
Ray Milkey | 97f8f10 | 2014-11-14 14:18:23 -0800 | [diff] [blame] | 17 | |
Ray Milkey | 97f8f10 | 2014-11-14 14:18:23 -0800 | [diff] [blame] | 18 | import org.junit.Test; |
Ray Milkey | 97f8f10 | 2014-11-14 14:18:23 -0800 | [diff] [blame] | 19 | import org.onlab.packet.IpAddress; |
| 20 | import org.onlab.packet.MacAddress; |
| 21 | import org.onlab.packet.VlanId; |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 22 | import org.onosproject.net.PortNumber; |
| 23 | import org.onosproject.net.flow.instructions.Instruction; |
Ray Milkey | 97f8f10 | 2014-11-14 14:18:23 -0800 | [diff] [blame] | 24 | |
alshabib | 346b5b3 | 2015-03-06 00:42:16 -0800 | [diff] [blame] | 25 | import java.util.List; |
Ray Milkey | 97f8f10 | 2014-11-14 14:18:23 -0800 | [diff] [blame] | 26 | |
Ray Milkey | 97f8f10 | 2014-11-14 14:18:23 -0800 | [diff] [blame] | 27 | import static org.hamcrest.MatcherAssert.assertThat; |
| 28 | import static org.hamcrest.Matchers.hasSize; |
Ray Milkey | 97f8f10 | 2014-11-14 14:18:23 -0800 | [diff] [blame] | 29 | |
| 30 | /** |
| 31 | * Unit tests for the DefaultTrafficTreatment class. |
| 32 | */ |
| 33 | public class DefaultTrafficTreatmentTest { |
| 34 | |
| 35 | // Tests for the nested Builder class |
| 36 | |
| 37 | /** |
Ray Milkey | 97f8f10 | 2014-11-14 14:18:23 -0800 | [diff] [blame] | 38 | * Tests methods defined on the Builder. |
| 39 | */ |
| 40 | @Test |
| 41 | public void testBuilderMethods() { |
Ray Milkey | 97f8f10 | 2014-11-14 14:18:23 -0800 | [diff] [blame] | 42 | final TrafficTreatment.Builder builder1 = |
| 43 | DefaultTrafficTreatment.builder() |
Ray Milkey | 97f8f10 | 2014-11-14 14:18:23 -0800 | [diff] [blame] | 44 | .setEthDst(MacAddress.BROADCAST) |
| 45 | .setEthSrc(MacAddress.BROADCAST) |
| 46 | .setIpDst(IpAddress.valueOf("1.1.1.1")) |
| 47 | .setIpSrc(IpAddress.valueOf("2.2.2.2")) |
Ray Milkey | 97f8f10 | 2014-11-14 14:18:23 -0800 | [diff] [blame] | 48 | .setOutput(PortNumber.portNumber(2)) |
| 49 | .setVlanId(VlanId.vlanId((short) 4)) |
| 50 | .setVlanPcp((byte) 3); |
| 51 | |
| 52 | final TrafficTreatment treatment1 = builder1.build(); |
| 53 | |
Ray Milkey | 4250735 | 2015-03-20 15:16:10 -0700 | [diff] [blame] | 54 | final List<Instruction> instructions1 = treatment1.immediate(); |
Sho SHIMIZU | a114d89 | 2016-03-11 16:48:19 -0800 | [diff] [blame] | 55 | assertThat(instructions1, hasSize(7)); |
Ray Milkey | 97f8f10 | 2014-11-14 14:18:23 -0800 | [diff] [blame] | 56 | |
| 57 | builder1.drop(); |
Ray Milkey | 97f8f10 | 2014-11-14 14:18:23 -0800 | [diff] [blame] | 58 | |
Ray Milkey | 4250735 | 2015-03-20 15:16:10 -0700 | [diff] [blame] | 59 | final List<Instruction> instructions2 = builder1.build().immediate(); |
Sho SHIMIZU | a114d89 | 2016-03-11 16:48:19 -0800 | [diff] [blame] | 60 | assertThat(instructions2, hasSize(8)); |
Ray Milkey | 4250735 | 2015-03-20 15:16:10 -0700 | [diff] [blame] | 61 | |
| 62 | builder1.deferred() |
| 63 | .popVlan() |
| 64 | .pushVlan() |
| 65 | .setVlanId(VlanId.vlanId((short) 5)); |
| 66 | |
| 67 | final List<Instruction> instructions3 = builder1.build().immediate(); |
Sho SHIMIZU | a114d89 | 2016-03-11 16:48:19 -0800 | [diff] [blame] | 68 | assertThat(instructions3, hasSize(8)); |
Ray Milkey | 4250735 | 2015-03-20 15:16:10 -0700 | [diff] [blame] | 69 | final List<Instruction> instructions4 = builder1.build().deferred(); |
| 70 | assertThat(instructions4, hasSize(3)); |
Ray Milkey | 97f8f10 | 2014-11-14 14:18:23 -0800 | [diff] [blame] | 71 | } |
Ray Milkey | 97f8f10 | 2014-11-14 14:18:23 -0800 | [diff] [blame] | 72 | } |