Shashikanth VH
Committed by Gerrit Code Review

[ONOS-3856] BGP flow specification RIB out test.

Change-Id: Ie4d2ef90c261f8bb5b560cb2b62c5cf7cca29988
/*
* Copyright 2016 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.bgpio.protocol.flowspec;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import org.junit.Test;
import org.onosproject.bgpio.types.BgpFsActionTrafficRate;
import org.onosproject.bgpio.types.BgpFsOperatorValue;
import org.onosproject.bgpio.types.BgpFsPortNum;
import org.onosproject.bgpio.types.BgpValueType;
import com.google.common.testing.EqualsTester;
/**
* Test for BgpFlowSpecDetails flow specification.
*/
public class BgpFlowSpecDetailsTest {
List<BgpValueType> flowSpecComponents1 = new LinkedList<>();
private List<BgpFsOperatorValue> operatorValue1 = new ArrayList<>();
BgpFlowSpecDetails flowSpecDetails1 = new BgpFlowSpecDetails(flowSpecComponents1);
BgpFsPortNum portNum1 = new BgpFsPortNum(operatorValue1);
List<BgpValueType> flowSpecComponents = new LinkedList<>();
private List<BgpFsOperatorValue> operatorValue = new ArrayList<>();
BgpFlowSpecDetails flowSpecDetails = new BgpFlowSpecDetails(flowSpecComponents);
BgpFsPortNum portNum = new BgpFsPortNum(operatorValue);
List<BgpValueType> flowSpecComponents2 = new LinkedList<>();
private List<BgpFsOperatorValue> operatorValue2 = new ArrayList<>();
BgpFlowSpecDetails flowSpecDetails2 = new BgpFlowSpecDetails(flowSpecComponents2);
BgpFsPortNum portNum2 = new BgpFsPortNum(operatorValue2);
@Test
public void testEquality() {
flowSpecComponents1.add(portNum1);
byte[] port1 = new byte[] {(byte) 0x1 };
operatorValue1.add(new BgpFsOperatorValue((byte) 0x81, port1));
byte[] port11 = new byte[] {(byte) 0x1 };
operatorValue1.add(new BgpFsOperatorValue((byte) 0x82, port11));
flowSpecDetails1.setFsActionTlv(new BgpFsActionTrafficRate((short) 1, 1));
flowSpecComponents.add(portNum);
byte[] port = new byte[] {(byte) 0x1 };
operatorValue.add(new BgpFsOperatorValue((byte) 0x81, port));
byte[] port4 = new byte[] {(byte) 0x1 };
operatorValue.add(new BgpFsOperatorValue((byte) 0x82, port4));
flowSpecDetails.setFsActionTlv(new BgpFsActionTrafficRate((short) 1, 1));
flowSpecComponents2.add(portNum2);
byte[] port2 = new byte[] {(byte) 0x1 };
operatorValue2.add(new BgpFsOperatorValue((byte) 0x82, port2));
byte[] port22 = new byte[] {(byte) 0x1 };
operatorValue2.add(new BgpFsOperatorValue((byte) 0x82, port22));
flowSpecDetails2.setFsActionTlv(new BgpFsActionTrafficRate((short) 1, 1));
new EqualsTester()
.addEqualityGroup(flowSpecDetails1, flowSpecDetails)
.addEqualityGroup(flowSpecDetails2)
.testEquals();
}
}
/*
* Copyright 2016 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.controller.impl;
import org.junit.Test;
import org.onlab.packet.IpAddress;
import org.onlab.packet.IpPrefix;
import org.onosproject.bgp.controller.impl.BgpFlowSpecRibOut;
import org.onosproject.bgpio.protocol.flowspec.BgpFlowSpecDetails;
import org.onosproject.bgpio.protocol.flowspec.BgpFlowSpecPrefix;
import org.onosproject.bgpio.types.BgpFsOperatorValue;
import org.onosproject.bgpio.types.BgpFsPortNum;
import org.onosproject.bgpio.types.BgpValueType;
import org.onosproject.bgpio.types.RouteDistinguisher;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
/**
* Test cases for BGP Selection Algorithm.
*/
public class BgpFlowSpecRibOutTest {
/**
* Add flow specification to rib out.
*/
@Test
public void bgpFlowSpecRibOutTests1() {
List<BgpValueType> flowSpecComponents = new LinkedList<>();
List<BgpFsOperatorValue> operatorValue = new ArrayList<>();
BgpFlowSpecRibOut ribOut = new BgpFlowSpecRibOut();
IpPrefix destinationPrefix = IpPrefix.valueOf(IpAddress.valueOf("10.0.1.1"), 32);
IpPrefix sourcePrefix = IpPrefix.valueOf(IpAddress.valueOf("10.0.1.2"), 32);
BgpFlowSpecPrefix prefix = new BgpFlowSpecPrefix(destinationPrefix, sourcePrefix);
byte[] port = new byte[] {(byte) 0x1 };
operatorValue.add(new BgpFsOperatorValue((byte) 0x81, port));
BgpFsPortNum portNum = new BgpFsPortNum(operatorValue);
flowSpecComponents.add(portNum);
BgpFlowSpecDetails flowSpec = new BgpFlowSpecDetails(flowSpecComponents);
ribOut.add(prefix, flowSpec);
boolean isPresent = ribOut.flowSpecTree().containsKey(prefix);
assertThat(isPresent, is(true));
}
/**
* Add and delete flow specification to rib out.
*/
@Test
public void bgpFlowSpecRibOutTest2() {
List<BgpValueType> flowSpecComponents = new LinkedList<>();
List<BgpFsOperatorValue> operatorValue = new ArrayList<>();
BgpFlowSpecRibOut ribOut = new BgpFlowSpecRibOut();
IpPrefix destinationPrefix = IpPrefix.valueOf(IpAddress.valueOf("10.0.1.1"), 32);
IpPrefix sourcePrefix = IpPrefix.valueOf(IpAddress.valueOf("10.0.1.2"), 32);
BgpFlowSpecPrefix prefix = new BgpFlowSpecPrefix(destinationPrefix, sourcePrefix);
byte[] port = new byte[] {(byte) 0x1 };
operatorValue.add(new BgpFsOperatorValue((byte) 0x81, port));
BgpFsPortNum portNum = new BgpFsPortNum(operatorValue);
flowSpecComponents.add(portNum);
BgpFlowSpecDetails flowSpec = new BgpFlowSpecDetails(flowSpecComponents);
ribOut.add(prefix, flowSpec);
boolean isPresent = ribOut.flowSpecTree().containsKey(prefix);
assertThat(isPresent, is(true));
ribOut.delete(prefix);
isPresent = ribOut.flowSpecTree().containsKey(prefix);
assertThat(isPresent, is(false));
}
/**
* Add and delete flow specification with a specific VPN to rib out.
*/
@Test
public void bgpFlowSpecRibOutTest3() {
List<BgpValueType> flowSpecComponents = new LinkedList<>();
List<BgpFsOperatorValue> operatorValue = new ArrayList<>();
RouteDistinguisher routeDistinguisher = new RouteDistinguisher(1);
BgpFlowSpecRibOut ribOut = new BgpFlowSpecRibOut();
IpPrefix destinationPrefix = IpPrefix.valueOf(IpAddress.valueOf("10.0.1.1"), 32);
IpPrefix sourcePrefix = IpPrefix.valueOf(IpAddress.valueOf("10.0.1.2"), 32);
BgpFlowSpecPrefix prefix = new BgpFlowSpecPrefix(destinationPrefix, sourcePrefix);
byte[] port = new byte[] {(byte) 0x1 };
operatorValue.add(new BgpFsOperatorValue((byte) 0x81, port));
BgpFsPortNum portNum = new BgpFsPortNum(operatorValue);
flowSpecComponents.add(portNum);
BgpFlowSpecDetails flowSpec = new BgpFlowSpecDetails(flowSpecComponents);
ribOut.add(routeDistinguisher, prefix, flowSpec);
boolean isPresent = ribOut.vpnFlowSpecTree().containsKey(routeDistinguisher);
assertThat(isPresent, is(true));
ribOut.delete(routeDistinguisher, prefix);
isPresent = ribOut.vpnFlowSpecTree().containsKey(routeDistinguisher);
assertThat(isPresent, is(false));
}
}