Shashikanth VH | ae8f63d | 2016-02-10 11:46:09 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame^] | 2 | * Copyright 2016-present Open Networking Laboratory |
Shashikanth VH | ae8f63d | 2016-02-10 11:46:09 +0530 | [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 | */ |
| 16 | package org.onosproject.controller.impl; |
| 17 | |
| 18 | import org.junit.Test; |
| 19 | import org.onlab.packet.IpAddress; |
| 20 | import org.onlab.packet.IpPrefix; |
Shashikanth VH | e3a73bc | 2016-02-22 20:11:31 +0530 | [diff] [blame] | 21 | import org.onosproject.bgp.controller.impl.BgpFlowSpecRib; |
Shashikanth VH | ae8f63d | 2016-02-10 11:46:09 +0530 | [diff] [blame] | 22 | import org.onosproject.bgpio.protocol.flowspec.BgpFlowSpecDetails; |
| 23 | import org.onosproject.bgpio.protocol.flowspec.BgpFlowSpecPrefix; |
| 24 | import org.onosproject.bgpio.types.BgpFsOperatorValue; |
| 25 | import org.onosproject.bgpio.types.BgpFsPortNum; |
| 26 | import org.onosproject.bgpio.types.BgpValueType; |
| 27 | import org.onosproject.bgpio.types.RouteDistinguisher; |
| 28 | |
| 29 | import java.util.ArrayList; |
| 30 | import java.util.LinkedList; |
| 31 | import java.util.List; |
| 32 | |
| 33 | import static org.hamcrest.MatcherAssert.assertThat; |
| 34 | import static org.hamcrest.core.Is.is; |
| 35 | |
| 36 | /** |
| 37 | * Test cases for BGP Selection Algorithm. |
| 38 | */ |
Shashikanth VH | e3a73bc | 2016-02-22 20:11:31 +0530 | [diff] [blame] | 39 | public class BgpFlowSpecRibTest { |
Shashikanth VH | ae8f63d | 2016-02-10 11:46:09 +0530 | [diff] [blame] | 40 | |
| 41 | /** |
Shashikanth VH | e3a73bc | 2016-02-22 20:11:31 +0530 | [diff] [blame] | 42 | * Add flow specification to rib. |
Shashikanth VH | ae8f63d | 2016-02-10 11:46:09 +0530 | [diff] [blame] | 43 | */ |
| 44 | @Test |
Shashikanth VH | e3a73bc | 2016-02-22 20:11:31 +0530 | [diff] [blame] | 45 | public void bgpFlowSpecRibTests1() { |
Shashikanth VH | ae8f63d | 2016-02-10 11:46:09 +0530 | [diff] [blame] | 46 | List<BgpValueType> flowSpecComponents = new LinkedList<>(); |
| 47 | List<BgpFsOperatorValue> operatorValue = new ArrayList<>(); |
Shashikanth VH | e3a73bc | 2016-02-22 20:11:31 +0530 | [diff] [blame] | 48 | BgpFlowSpecRib rib = new BgpFlowSpecRib(); |
Shashikanth VH | ae8f63d | 2016-02-10 11:46:09 +0530 | [diff] [blame] | 49 | |
| 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 VH | e3a73bc | 2016-02-22 20:11:31 +0530 | [diff] [blame] | 63 | rib.add(prefix, flowSpec); |
Shashikanth VH | ae8f63d | 2016-02-10 11:46:09 +0530 | [diff] [blame] | 64 | |
Shashikanth VH | e3a73bc | 2016-02-22 20:11:31 +0530 | [diff] [blame] | 65 | boolean isPresent = rib.flowSpecTree().containsKey(prefix); |
Shashikanth VH | ae8f63d | 2016-02-10 11:46:09 +0530 | [diff] [blame] | 66 | assertThat(isPresent, is(true)); |
| 67 | } |
| 68 | |
| 69 | /** |
Shashikanth VH | e3a73bc | 2016-02-22 20:11:31 +0530 | [diff] [blame] | 70 | * Add and delete flow specification to rib. |
Shashikanth VH | ae8f63d | 2016-02-10 11:46:09 +0530 | [diff] [blame] | 71 | */ |
| 72 | @Test |
Shashikanth VH | e3a73bc | 2016-02-22 20:11:31 +0530 | [diff] [blame] | 73 | public void bgpFlowSpecRibTest2() { |
Shashikanth VH | ae8f63d | 2016-02-10 11:46:09 +0530 | [diff] [blame] | 74 | List<BgpValueType> flowSpecComponents = new LinkedList<>(); |
| 75 | List<BgpFsOperatorValue> operatorValue = new ArrayList<>(); |
Shashikanth VH | e3a73bc | 2016-02-22 20:11:31 +0530 | [diff] [blame] | 76 | BgpFlowSpecRib rib = new BgpFlowSpecRib(); |
Shashikanth VH | ae8f63d | 2016-02-10 11:46:09 +0530 | [diff] [blame] | 77 | |
| 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 VH | e3a73bc | 2016-02-22 20:11:31 +0530 | [diff] [blame] | 90 | rib.add(prefix, flowSpec); |
Shashikanth VH | ae8f63d | 2016-02-10 11:46:09 +0530 | [diff] [blame] | 91 | |
Shashikanth VH | e3a73bc | 2016-02-22 20:11:31 +0530 | [diff] [blame] | 92 | boolean isPresent = rib.flowSpecTree().containsKey(prefix); |
Shashikanth VH | ae8f63d | 2016-02-10 11:46:09 +0530 | [diff] [blame] | 93 | assertThat(isPresent, is(true)); |
| 94 | |
Shashikanth VH | e3a73bc | 2016-02-22 20:11:31 +0530 | [diff] [blame] | 95 | rib.delete(prefix); |
| 96 | isPresent = rib.flowSpecTree().containsKey(prefix); |
Shashikanth VH | ae8f63d | 2016-02-10 11:46:09 +0530 | [diff] [blame] | 97 | assertThat(isPresent, is(false)); |
| 98 | |
| 99 | } |
| 100 | |
| 101 | /** |
Shashikanth VH | e3a73bc | 2016-02-22 20:11:31 +0530 | [diff] [blame] | 102 | * Add and delete flow specification with a specific VPN to rib. |
Shashikanth VH | ae8f63d | 2016-02-10 11:46:09 +0530 | [diff] [blame] | 103 | */ |
| 104 | @Test |
Shashikanth VH | e3a73bc | 2016-02-22 20:11:31 +0530 | [diff] [blame] | 105 | public void bgpFlowSpecRibTest3() { |
Shashikanth VH | ae8f63d | 2016-02-10 11:46:09 +0530 | [diff] [blame] | 106 | List<BgpValueType> flowSpecComponents = new LinkedList<>(); |
| 107 | List<BgpFsOperatorValue> operatorValue = new ArrayList<>(); |
| 108 | RouteDistinguisher routeDistinguisher = new RouteDistinguisher(1); |
Shashikanth VH | e3a73bc | 2016-02-22 20:11:31 +0530 | [diff] [blame] | 109 | BgpFlowSpecRib rib = new BgpFlowSpecRib(); |
Shashikanth VH | ae8f63d | 2016-02-10 11:46:09 +0530 | [diff] [blame] | 110 | |
| 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 VH | e3a73bc | 2016-02-22 20:11:31 +0530 | [diff] [blame] | 124 | rib.add(routeDistinguisher, prefix, flowSpec); |
Shashikanth VH | ae8f63d | 2016-02-10 11:46:09 +0530 | [diff] [blame] | 125 | |
Shashikanth VH | e3a73bc | 2016-02-22 20:11:31 +0530 | [diff] [blame] | 126 | boolean isPresent = rib.vpnFlowSpecTree().containsKey(routeDistinguisher); |
Shashikanth VH | ae8f63d | 2016-02-10 11:46:09 +0530 | [diff] [blame] | 127 | assertThat(isPresent, is(true)); |
| 128 | |
Shashikanth VH | e3a73bc | 2016-02-22 20:11:31 +0530 | [diff] [blame] | 129 | rib.delete(routeDistinguisher, prefix); |
| 130 | isPresent = rib.vpnFlowSpecTree().containsKey(routeDistinguisher); |
Shashikanth VH | ae8f63d | 2016-02-10 11:46:09 +0530 | [diff] [blame] | 131 | assertThat(isPresent, is(false)); |
| 132 | } |
| 133 | } |