Shashikanth VH
Committed by Gerrit Code Review

[ONOS-3857] BGP flow specification action components tlv.

Change-Id: I15d8be18aa568520ead48d46dc9ba71e99b658e8
/*
* 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.types;
import java.util.Arrays;
import org.onosproject.bgpio.util.Constants;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.bgpio.exceptions.BgpParseException;
import com.google.common.base.MoreObjects;
/**
* Provides implementation of BGP flow specification action.
*/
public class BgpFsActionReDirect implements BgpValueType {
public static final short TYPE = Constants.BGP_FLOWSPEC_ACTION_TRAFFIC_REDIRECT;
private byte[] routeTarget;
/**
* Constructor to initialize the value.
*
* @param routeTarget route target
*/
public BgpFsActionReDirect(byte[] routeTarget) {
this.routeTarget = Arrays.copyOf(routeTarget, routeTarget.length);
}
@Override
public short getType() {
return this.TYPE;
}
@Override
public int hashCode() {
return Arrays.hashCode(routeTarget);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof BgpFsActionReDirect) {
BgpFsActionReDirect other = (BgpFsActionReDirect) obj;
return Arrays.equals(this.routeTarget, other.routeTarget);
}
return false;
}
@Override
public int write(ChannelBuffer cb) {
int iLenStartIndex = cb.writerIndex();
cb.writeShort(TYPE);
cb.writeBytes(routeTarget);
return cb.writerIndex() - iLenStartIndex;
}
/**
* Reads the channel buffer and returns object.
*
* @param cb channelBuffer
* @param type address type
* @return object of flow spec action redirect
* @throws BgpParseException while parsing BgpFsActionReDirect
*/
public static BgpFsActionReDirect read(ChannelBuffer cb, short type) throws BgpParseException {
return null;
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.add("TYPE", TYPE)
.add("routeTarget", routeTarget).toString();
}
@Override
public int compareTo(Object o) {
// TODO Auto-generated method stub
return 0;
}
}
/*
* 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.types;
import java.util.Arrays;
import org.onosproject.bgpio.util.Constants;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.bgpio.exceptions.BgpParseException;
import com.google.common.base.MoreObjects;
/**
* Provides implementation of BGP flow specification action.
*/
public class BgpFsActionTrafficAction implements BgpValueType {
public static final short TYPE = Constants.BGP_FLOWSPEC_ACTION_TRAFFIC_ACTION;
private byte[] bitMask;
/**
* Constructor to initialize the value.
*
* @param bitMask traffic action bit mask
*/
public BgpFsActionTrafficAction(byte[] bitMask) {
this.bitMask = Arrays.copyOf(bitMask, bitMask.length);
}
@Override
public short getType() {
return this.TYPE;
}
@Override
public int hashCode() {
return Arrays.hashCode(bitMask);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof BgpFsActionTrafficAction) {
BgpFsActionTrafficAction other = (BgpFsActionTrafficAction) obj;
return Arrays.equals(this.bitMask, other.bitMask);
}
return false;
}
@Override
public int write(ChannelBuffer cb) {
int iLenStartIndex = cb.writerIndex();
cb.writeShort(TYPE);
cb.writeBytes(bitMask);
return cb.writerIndex() - iLenStartIndex;
}
/**
* Reads the channel buffer and returns object.
*
* @param cb channelBuffer
* @param type address type
* @return object of flow spec action traffic rate
* @throws BgpParseException while parsing BgpFsActionTrafficAction
*/
public static BgpFsActionTrafficAction read(ChannelBuffer cb, short type) throws BgpParseException {
return null;
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.add("TYPE", TYPE)
.add("bitMask", bitMask).toString();
}
@Override
public int compareTo(Object o) {
// TODO Auto-generated method stub
return 0;
}
}
/*
* 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.types;
import java.util.Arrays;
import org.onosproject.bgpio.util.Constants;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.bgpio.exceptions.BgpParseException;
import com.google.common.base.MoreObjects;
/**
* Provides implementation of BGP flow specification action.
*/
public class BgpFsActionTrafficMarking implements BgpValueType {
public static final short TYPE = Constants.BGP_FLOWSPEC_ACTION_TRAFFIC_MARKING;
private byte[] dscpValue;
/**
* Constructor to initialize the value.
*
* @param dscpValue DSCP value
*/
public BgpFsActionTrafficMarking(byte[] dscpValue) {
this.dscpValue = Arrays.copyOf(dscpValue, dscpValue.length);
}
@Override
public short getType() {
return this.TYPE;
}
@Override
public int hashCode() {
return Arrays.hashCode(dscpValue);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof BgpFsActionTrafficMarking) {
BgpFsActionTrafficMarking other = (BgpFsActionTrafficMarking) obj;
return Arrays.equals(this.dscpValue, other.dscpValue);
}
return false;
}
@Override
public int write(ChannelBuffer cb) {
int iLenStartIndex = cb.writerIndex();
cb.writeShort(TYPE);
cb.writeBytes(dscpValue);
return cb.writerIndex() - iLenStartIndex;
}
/**
* Reads the channel buffer and returns object.
*
* @param cb channelBuffer
* @param type address type
* @return object of flow spec action traffic marking
* @throws BgpParseException while parsing BgpFsActionTrafficMarking
*/
public static BgpFsActionTrafficMarking read(ChannelBuffer cb, short type) throws BgpParseException {
return null;
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.add("TYPE", TYPE)
.add("dscpValue", dscpValue).toString();
}
@Override
public int compareTo(Object o) {
// TODO Auto-generated method stub
return 0;
}
}
/*
* 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.types;
import java.util.Objects;
import org.onosproject.bgpio.util.Constants;
import org.jboss.netty.buffer.ChannelBuffer;
import org.onosproject.bgpio.exceptions.BgpParseException;
import com.google.common.base.MoreObjects;
/**
* Provides implementation of BGP flow specification action.
*/
public class BgpFsActionTrafficRate implements BgpValueType {
public static final short TYPE = Constants.BGP_FLOWSPEC_ACTION_TRAFFIC_RATE;
private short asn;
private float rate;
/**
* Constructor to initialize the value.
*
* @param asn autonomous system number
* @param rate traffic rate
*/
public BgpFsActionTrafficRate(short asn, float rate) {
this.asn = asn;
this.rate = rate;
}
@Override
public short getType() {
return this.TYPE;
}
@Override
public int hashCode() {
return Objects.hash(asn, rate);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof BgpFsActionTrafficRate) {
BgpFsActionTrafficRate other = (BgpFsActionTrafficRate) obj;
return Objects.equals(this.asn, other.asn) && Objects.equals(this.rate, other.rate);
}
return false;
}
@Override
public int write(ChannelBuffer cb) {
int iLenStartIndex = cb.writerIndex();
cb.writeShort(TYPE);
cb.writeShort(asn);
cb.writeFloat(rate);
return cb.writerIndex() - iLenStartIndex;
}
/**
* Reads the channel buffer and returns object.
*
* @param cb channelBuffer
* @param type address type
* @return object of flow spec action traffic rate
* @throws BgpParseException while parsing BgpFsActionTrafficRate
*/
public static BgpFsActionTrafficRate read(ChannelBuffer cb, short type) throws BgpParseException {
return null;
}
@Override
public String toString() {
return MoreObjects.toStringHelper(getClass())
.add("TYPE", TYPE)
.add("asn", asn)
.add("rate", rate).toString();
}
@Override
public int compareTo(Object o) {
// TODO Auto-generated method stub
return 0;
}
}
/*
* 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.types;
import org.junit.Test;
import com.google.common.testing.EqualsTester;
/**
* Test for action redirect flow specification component.
*/
public class BgpFsActionReDirectTest {
private final BgpFsActionReDirect tlv1 = new BgpFsActionReDirect(new byte[100]);
private final BgpFsActionReDirect sameAsTlv1 = new BgpFsActionReDirect(new byte[100]);
private final BgpFsActionReDirect tlv2 = new BgpFsActionReDirect(new byte[200]);
@Test
public void testEquality() {
new EqualsTester()
.addEqualityGroup(tlv1, sameAsTlv1)
.addEqualityGroup(tlv2)
.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.bgpio.types;
import org.junit.Test;
import com.google.common.testing.EqualsTester;
/**
* Test for traffic action flow specification component.
*/
public class BgpFsActionTrafficActionTest {
private final BgpFsActionTrafficAction tlv1 = new BgpFsActionTrafficAction(new byte[100]);
private final BgpFsActionTrafficAction sameAsTlv1 = new BgpFsActionTrafficAction(new byte[100]);
private final BgpFsActionTrafficAction tlv2 = new BgpFsActionTrafficAction(new byte[200]);
@Test
public void testEquality() {
new EqualsTester()
.addEqualityGroup(tlv1, sameAsTlv1)
.addEqualityGroup(tlv2)
.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.bgpio.types;
import org.junit.Test;
import com.google.common.testing.EqualsTester;
/**
* Test for action traffic marking flow specification component.
*/
public class BgpFsActionTrafficMarkingTest {
private final BgpFsActionTrafficMarking tlv1 = new BgpFsActionTrafficMarking(new byte[100]);
private final BgpFsActionTrafficMarking sameAsTlv1 = new BgpFsActionTrafficMarking(new byte[100]);
private final BgpFsActionTrafficMarking tlv2 = new BgpFsActionTrafficMarking(new byte[200]);
@Test
public void testEquality() {
new EqualsTester()
.addEqualityGroup(tlv1, sameAsTlv1)
.addEqualityGroup(tlv2)
.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.bgpio.types;
import org.junit.Test;
import com.google.common.testing.EqualsTester;
/**
* Test for action traffic rate flow specification component.
*/
public class BgpFsActionTrafficRateTest {
private final BgpFsActionTrafficRate tlv1 = new BgpFsActionTrafficRate((short) 1, (float) 1.2);
private final BgpFsActionTrafficRate sameAsTlv1 = new BgpFsActionTrafficRate((short) 1, (float) 1.2);
private final BgpFsActionTrafficRate tlv2 = new BgpFsActionTrafficRate((short) 2, (float) 1.2);
@Test
public void testEquality() {
new EqualsTester()
.addEqualityGroup(tlv1, sameAsTlv1)
.addEqualityGroup(tlv2)
.testEquals();
}
}