blob: ec3445323753920ab1304e75fe70ed865f566e72 [file] [log] [blame]
Ray Milkey97f8f102014-11-14 14:18:23 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2014-present Open Networking Laboratory
Ray Milkey97f8f102014-11-14 14:18:23 -08003 *
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'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.net.flow;
Ray Milkey97f8f102014-11-14 14:18:23 -080017
Ray Milkey97f8f102014-11-14 14:18:23 -080018import org.junit.Test;
Ray Milkey97f8f102014-11-14 14:18:23 -080019import org.onlab.packet.IpAddress;
20import org.onlab.packet.MacAddress;
21import org.onlab.packet.VlanId;
alshabib346b5b32015-03-06 00:42:16 -080022import org.onosproject.net.PortNumber;
23import org.onosproject.net.flow.instructions.Instruction;
Ray Milkey97f8f102014-11-14 14:18:23 -080024
alshabib346b5b32015-03-06 00:42:16 -080025import java.util.List;
Ray Milkey97f8f102014-11-14 14:18:23 -080026
Ray Milkey97f8f102014-11-14 14:18:23 -080027import static org.hamcrest.MatcherAssert.assertThat;
28import static org.hamcrest.Matchers.hasSize;
Ray Milkey97f8f102014-11-14 14:18:23 -080029
30/**
31 * Unit tests for the DefaultTrafficTreatment class.
32 */
33public class DefaultTrafficTreatmentTest {
34
35 // Tests for the nested Builder class
36
37 /**
Ray Milkey97f8f102014-11-14 14:18:23 -080038 * Tests methods defined on the Builder.
39 */
40 @Test
41 public void testBuilderMethods() {
Ray Milkey97f8f102014-11-14 14:18:23 -080042 final TrafficTreatment.Builder builder1 =
43 DefaultTrafficTreatment.builder()
Ray Milkey97f8f102014-11-14 14:18:23 -080044 .setEthDst(MacAddress.BROADCAST)
45 .setEthSrc(MacAddress.BROADCAST)
46 .setIpDst(IpAddress.valueOf("1.1.1.1"))
47 .setIpSrc(IpAddress.valueOf("2.2.2.2"))
Ray Milkey97f8f102014-11-14 14:18:23 -080048 .setOutput(PortNumber.portNumber(2))
49 .setVlanId(VlanId.vlanId((short) 4))
50 .setVlanPcp((byte) 3);
51
52 final TrafficTreatment treatment1 = builder1.build();
53
Ray Milkey42507352015-03-20 15:16:10 -070054 final List<Instruction> instructions1 = treatment1.immediate();
Sho SHIMIZUa114d892016-03-11 16:48:19 -080055 assertThat(instructions1, hasSize(7));
Ray Milkey97f8f102014-11-14 14:18:23 -080056
57 builder1.drop();
Ray Milkey97f8f102014-11-14 14:18:23 -080058
Ray Milkey42507352015-03-20 15:16:10 -070059 final List<Instruction> instructions2 = builder1.build().immediate();
Sho SHIMIZUa114d892016-03-11 16:48:19 -080060 assertThat(instructions2, hasSize(8));
Ray Milkey42507352015-03-20 15:16:10 -070061
62 builder1.deferred()
63 .popVlan()
64 .pushVlan()
65 .setVlanId(VlanId.vlanId((short) 5));
66
67 final List<Instruction> instructions3 = builder1.build().immediate();
Sho SHIMIZUa114d892016-03-11 16:48:19 -080068 assertThat(instructions3, hasSize(8));
Ray Milkey42507352015-03-20 15:16:10 -070069 final List<Instruction> instructions4 = builder1.build().deferred();
70 assertThat(instructions4, hasSize(3));
Ray Milkey97f8f102014-11-14 14:18:23 -080071 }
Ray Milkey97f8f102014-11-14 14:18:23 -080072}