blob: 8998dbecc01e52df33792de4401a2b85748577ea [file] [log] [blame]
Shashikanth VHae8f63d2016-02-10 11:46:09 +05301/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Shashikanth VHae8f63d2016-02-10 11:46:09 +05303 *
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 */
16package org.onosproject.controller.impl;
17
18import org.junit.Test;
19import org.onlab.packet.IpAddress;
20import org.onlab.packet.IpPrefix;
Shashikanth VHe3a73bc2016-02-22 20:11:31 +053021import org.onosproject.bgp.controller.impl.BgpFlowSpecRib;
Shashikanth VHae8f63d2016-02-10 11:46:09 +053022import org.onosproject.bgpio.protocol.flowspec.BgpFlowSpecDetails;
23import org.onosproject.bgpio.protocol.flowspec.BgpFlowSpecPrefix;
24import org.onosproject.bgpio.types.BgpFsOperatorValue;
25import org.onosproject.bgpio.types.BgpFsPortNum;
26import org.onosproject.bgpio.types.BgpValueType;
27import org.onosproject.bgpio.types.RouteDistinguisher;
28
29import java.util.ArrayList;
30import java.util.LinkedList;
31import java.util.List;
32
33import static org.hamcrest.MatcherAssert.assertThat;
34import static org.hamcrest.core.Is.is;
35
36/**
37 * Test cases for BGP Selection Algorithm.
38 */
Shashikanth VHe3a73bc2016-02-22 20:11:31 +053039public class BgpFlowSpecRibTest {
Shashikanth VHae8f63d2016-02-10 11:46:09 +053040
41 /**
Shashikanth VHe3a73bc2016-02-22 20:11:31 +053042 * Add flow specification to rib.
Shashikanth VHae8f63d2016-02-10 11:46:09 +053043 */
44 @Test
Shashikanth VHe3a73bc2016-02-22 20:11:31 +053045 public void bgpFlowSpecRibTests1() {
Shashikanth VHae8f63d2016-02-10 11:46:09 +053046 List<BgpValueType> flowSpecComponents = new LinkedList<>();
47 List<BgpFsOperatorValue> operatorValue = new ArrayList<>();
Shashikanth VHe3a73bc2016-02-22 20:11:31 +053048 BgpFlowSpecRib rib = new BgpFlowSpecRib();
Shashikanth VHae8f63d2016-02-10 11:46:09 +053049
50 IpPrefix destinationPrefix = IpPrefix.valueOf(IpAddress.valueOf("10.0.1.1"), 32);
51 IpPrefix sourcePrefix = IpPrefix.valueOf(IpAddress.valueOf("10.0.1.2"), 32);
52
53 BgpFlowSpecPrefix prefix = new BgpFlowSpecPrefix(destinationPrefix, sourcePrefix);
54
55 byte[] port = new byte[] {(byte) 0x1 };
56 operatorValue.add(new BgpFsOperatorValue((byte) 0x81, port));
57
58 BgpFsPortNum portNum = new BgpFsPortNum(operatorValue);
59 flowSpecComponents.add(portNum);
60
61 BgpFlowSpecDetails flowSpec = new BgpFlowSpecDetails(flowSpecComponents);
62
Shashikanth VHe3a73bc2016-02-22 20:11:31 +053063 rib.add(prefix, flowSpec);
Shashikanth VHae8f63d2016-02-10 11:46:09 +053064
Shashikanth VHe3a73bc2016-02-22 20:11:31 +053065 boolean isPresent = rib.flowSpecTree().containsKey(prefix);
Shashikanth VHae8f63d2016-02-10 11:46:09 +053066 assertThat(isPresent, is(true));
67 }
68
69 /**
Shashikanth VHe3a73bc2016-02-22 20:11:31 +053070 * Add and delete flow specification to rib.
Shashikanth VHae8f63d2016-02-10 11:46:09 +053071 */
72 @Test
Shashikanth VHe3a73bc2016-02-22 20:11:31 +053073 public void bgpFlowSpecRibTest2() {
Shashikanth VHae8f63d2016-02-10 11:46:09 +053074 List<BgpValueType> flowSpecComponents = new LinkedList<>();
75 List<BgpFsOperatorValue> operatorValue = new ArrayList<>();
Shashikanth VHe3a73bc2016-02-22 20:11:31 +053076 BgpFlowSpecRib rib = new BgpFlowSpecRib();
Shashikanth VHae8f63d2016-02-10 11:46:09 +053077
78 IpPrefix destinationPrefix = IpPrefix.valueOf(IpAddress.valueOf("10.0.1.1"), 32);
79 IpPrefix sourcePrefix = IpPrefix.valueOf(IpAddress.valueOf("10.0.1.2"), 32);
80
81 BgpFlowSpecPrefix prefix = new BgpFlowSpecPrefix(destinationPrefix, sourcePrefix);
82 byte[] port = new byte[] {(byte) 0x1 };
83 operatorValue.add(new BgpFsOperatorValue((byte) 0x81, port));
84
85 BgpFsPortNum portNum = new BgpFsPortNum(operatorValue);
86 flowSpecComponents.add(portNum);
87
88 BgpFlowSpecDetails flowSpec = new BgpFlowSpecDetails(flowSpecComponents);
89
Shashikanth VHe3a73bc2016-02-22 20:11:31 +053090 rib.add(prefix, flowSpec);
Shashikanth VHae8f63d2016-02-10 11:46:09 +053091
Shashikanth VHe3a73bc2016-02-22 20:11:31 +053092 boolean isPresent = rib.flowSpecTree().containsKey(prefix);
Shashikanth VHae8f63d2016-02-10 11:46:09 +053093 assertThat(isPresent, is(true));
94
Shashikanth VHe3a73bc2016-02-22 20:11:31 +053095 rib.delete(prefix);
96 isPresent = rib.flowSpecTree().containsKey(prefix);
Shashikanth VHae8f63d2016-02-10 11:46:09 +053097 assertThat(isPresent, is(false));
98
99 }
100
101 /**
Shashikanth VHe3a73bc2016-02-22 20:11:31 +0530102 * Add and delete flow specification with a specific VPN to rib.
Shashikanth VHae8f63d2016-02-10 11:46:09 +0530103 */
104 @Test
Shashikanth VHe3a73bc2016-02-22 20:11:31 +0530105 public void bgpFlowSpecRibTest3() {
Shashikanth VHae8f63d2016-02-10 11:46:09 +0530106 List<BgpValueType> flowSpecComponents = new LinkedList<>();
107 List<BgpFsOperatorValue> operatorValue = new ArrayList<>();
108 RouteDistinguisher routeDistinguisher = new RouteDistinguisher(1);
Shashikanth VHe3a73bc2016-02-22 20:11:31 +0530109 BgpFlowSpecRib rib = new BgpFlowSpecRib();
Shashikanth VHae8f63d2016-02-10 11:46:09 +0530110
111 IpPrefix destinationPrefix = IpPrefix.valueOf(IpAddress.valueOf("10.0.1.1"), 32);
112 IpPrefix sourcePrefix = IpPrefix.valueOf(IpAddress.valueOf("10.0.1.2"), 32);
113
114 BgpFlowSpecPrefix prefix = new BgpFlowSpecPrefix(destinationPrefix, sourcePrefix);
115
116 byte[] port = new byte[] {(byte) 0x1 };
117 operatorValue.add(new BgpFsOperatorValue((byte) 0x81, port));
118
119 BgpFsPortNum portNum = new BgpFsPortNum(operatorValue);
120 flowSpecComponents.add(portNum);
121
122 BgpFlowSpecDetails flowSpec = new BgpFlowSpecDetails(flowSpecComponents);
123
Shashikanth VHe3a73bc2016-02-22 20:11:31 +0530124 rib.add(routeDistinguisher, prefix, flowSpec);
Shashikanth VHae8f63d2016-02-10 11:46:09 +0530125
Shashikanth VHe3a73bc2016-02-22 20:11:31 +0530126 boolean isPresent = rib.vpnFlowSpecTree().containsKey(routeDistinguisher);
Shashikanth VHae8f63d2016-02-10 11:46:09 +0530127 assertThat(isPresent, is(true));
128
Shashikanth VHe3a73bc2016-02-22 20:11:31 +0530129 rib.delete(routeDistinguisher, prefix);
130 isPresent = rib.vpnFlowSpecTree().containsKey(routeDistinguisher);
Shashikanth VHae8f63d2016-02-10 11:46:09 +0530131 assertThat(isPresent, is(false));
132 }
133}