Committed by
Gerrit Code Review
[ONOS-3856] BGP flow specification component classes.
Change-Id: Ib798fe31c66813644fd7c2844682377fb5644aad
Showing
8 changed files
with
636 additions
and
0 deletions
protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/BgpFsDestinationPortNum.java
0 → 100755
| 1 | +/* | ||
| 2 | + * Copyright 2016 Open Networking Laboratory | ||
| 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.bgpio.types; | ||
| 17 | + | ||
| 18 | +import java.util.Objects; | ||
| 19 | +import java.util.List; | ||
| 20 | +import org.jboss.netty.buffer.ChannelBuffer; | ||
| 21 | +import org.onosproject.bgpio.exceptions.BgpParseException; | ||
| 22 | +import org.onosproject.bgpio.util.Constants; | ||
| 23 | +import com.google.common.base.MoreObjects; | ||
| 24 | + | ||
| 25 | +/** | ||
| 26 | + * Provides implementation of BGP flow specification component. | ||
| 27 | + */ | ||
| 28 | +public class BgpFsDestinationPortNum implements BgpValueType { | ||
| 29 | + | ||
| 30 | + public static final byte FLOW_SPEC_TYPE = Constants.BGP_FLOWSPEC_DST_PORT; | ||
| 31 | + private List<BgpFsOperatorValue> operatorValue; | ||
| 32 | + | ||
| 33 | + /** | ||
| 34 | + * Constructor to initialize the value. | ||
| 35 | + * | ||
| 36 | + * @param operatorValue list of operator and value | ||
| 37 | + */ | ||
| 38 | + public BgpFsDestinationPortNum(List<BgpFsOperatorValue> operatorValue) { | ||
| 39 | + this.operatorValue = operatorValue; | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + @Override | ||
| 43 | + public short getType() { | ||
| 44 | + return this.FLOW_SPEC_TYPE; | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + @Override | ||
| 48 | + public int hashCode() { | ||
| 49 | + return Objects.hash(operatorValue); | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + @Override | ||
| 53 | + public boolean equals(Object obj) { | ||
| 54 | + if (this == obj) { | ||
| 55 | + return true; | ||
| 56 | + } | ||
| 57 | + if (obj instanceof BgpFsDestinationPortNum) { | ||
| 58 | + BgpFsDestinationPortNum other = (BgpFsDestinationPortNum) obj; | ||
| 59 | + return this.operatorValue.equals(other.operatorValue); | ||
| 60 | + } | ||
| 61 | + return false; | ||
| 62 | + } | ||
| 63 | + | ||
| 64 | + @Override | ||
| 65 | + public int write(ChannelBuffer cb) { | ||
| 66 | + int iLenStartIndex = cb.writerIndex(); | ||
| 67 | + cb.writeByte(FLOW_SPEC_TYPE); | ||
| 68 | + | ||
| 69 | + for (BgpFsOperatorValue fsOperVal : operatorValue) { | ||
| 70 | + cb.writeByte(fsOperVal.option()); | ||
| 71 | + cb.writeBytes(fsOperVal.value()); | ||
| 72 | + } | ||
| 73 | + | ||
| 74 | + return cb.writerIndex() - iLenStartIndex; | ||
| 75 | + } | ||
| 76 | + | ||
| 77 | + /** | ||
| 78 | + * Reads the channel buffer and returns object. | ||
| 79 | + * | ||
| 80 | + * @param cb channelBuffer | ||
| 81 | + * @param type address type | ||
| 82 | + * @return object of flow spec destination port number | ||
| 83 | + * @throws BgpParseException while parsing BgpFsDestinationPortNum | ||
| 84 | + */ | ||
| 85 | + public static BgpFsDestinationPortNum read(ChannelBuffer cb, short type) throws BgpParseException { | ||
| 86 | + return null; | ||
| 87 | + } | ||
| 88 | + | ||
| 89 | + @Override | ||
| 90 | + public String toString() { | ||
| 91 | + return MoreObjects.toStringHelper(getClass()) | ||
| 92 | + .add("FLOW_SPEC_TYPE", FLOW_SPEC_TYPE) | ||
| 93 | + .add("operatorValue", operatorValue).toString(); | ||
| 94 | + } | ||
| 95 | + | ||
| 96 | + @Override | ||
| 97 | + public int compareTo(Object o) { | ||
| 98 | + // TODO Auto-generated method stub | ||
| 99 | + return 0; | ||
| 100 | + } | ||
| 101 | +} |
protocols/bgp/bgpio/src/main/java/org/onosproject/bgpio/types/BgpFsDestinationPrefix.java
0 → 100755
| 1 | +/* | ||
| 2 | + * Copyright 2016 Open Networking Laboratory | ||
| 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.bgpio.types; | ||
| 17 | + | ||
| 18 | +import java.nio.ByteBuffer; | ||
| 19 | +import java.util.Objects; | ||
| 20 | + | ||
| 21 | +import org.jboss.netty.buffer.ChannelBuffer; | ||
| 22 | +import org.onlab.packet.IpPrefix; | ||
| 23 | +import org.onosproject.bgpio.exceptions.BgpParseException; | ||
| 24 | +import org.onosproject.bgpio.util.Constants; | ||
| 25 | +import com.google.common.base.MoreObjects; | ||
| 26 | +import com.google.common.base.Preconditions; | ||
| 27 | + | ||
| 28 | +/** | ||
| 29 | + * Provides implementation of IPv4AddressTlv. | ||
| 30 | + */ | ||
| 31 | +public class BgpFsDestinationPrefix implements BgpValueType { | ||
| 32 | + | ||
| 33 | + public static final byte FLOW_SPEC_TYPE = Constants.BGP_FLOWSPEC_DST_PREFIX; | ||
| 34 | + private byte length; | ||
| 35 | + private IpPrefix ipPrefix; | ||
| 36 | + | ||
| 37 | + /** | ||
| 38 | + * Constructor to initialize parameters. | ||
| 39 | + * | ||
| 40 | + * @param length length of the prefix | ||
| 41 | + * @param ipPrefix ip prefix | ||
| 42 | + */ | ||
| 43 | + public BgpFsDestinationPrefix(byte length, IpPrefix ipPrefix) { | ||
| 44 | + this.ipPrefix = Preconditions.checkNotNull(ipPrefix); | ||
| 45 | + this.length = length; | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + /** | ||
| 49 | + * Returns ip prefix. | ||
| 50 | + * | ||
| 51 | + * @return ipPrefix ip prefix | ||
| 52 | + */ | ||
| 53 | + public IpPrefix ipPrefix() { | ||
| 54 | + return ipPrefix; | ||
| 55 | + } | ||
| 56 | + | ||
| 57 | + @Override | ||
| 58 | + public short getType() { | ||
| 59 | + return FLOW_SPEC_TYPE; | ||
| 60 | + } | ||
| 61 | + | ||
| 62 | + @Override | ||
| 63 | + public int hashCode() { | ||
| 64 | + return Objects.hash(ipPrefix); | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + @Override | ||
| 68 | + public boolean equals(Object obj) { | ||
| 69 | + if (this == obj) { | ||
| 70 | + return true; | ||
| 71 | + } | ||
| 72 | + if (obj instanceof BgpFsDestinationPrefix) { | ||
| 73 | + BgpFsDestinationPrefix other = (BgpFsDestinationPrefix) obj; | ||
| 74 | + return Objects.equals(this.ipPrefix, other.ipPrefix); | ||
| 75 | + } | ||
| 76 | + return false; | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + @Override | ||
| 80 | + public int write(ChannelBuffer cb) { | ||
| 81 | + int iLenStartIndex = cb.writerIndex(); | ||
| 82 | + cb.writeByte(FLOW_SPEC_TYPE); | ||
| 83 | + cb.writeByte(length); | ||
| 84 | + cb.writeInt(ipPrefix.getIp4Prefix().address().toInt()); | ||
| 85 | + return cb.writerIndex() - iLenStartIndex; | ||
| 86 | + } | ||
| 87 | + | ||
| 88 | + /** | ||
| 89 | + * Reads the channel buffer and returns object of IPv4AddressTlv. | ||
| 90 | + * | ||
| 91 | + * @param cb channelBuffer | ||
| 92 | + * @param type address type | ||
| 93 | + * @return object of flow spec destination prefix | ||
| 94 | + * @throws BgpParseException while parsing BgpFsDestinationPrefix | ||
| 95 | + */ | ||
| 96 | + public static BgpFsDestinationPrefix read(ChannelBuffer cb, short type) throws BgpParseException { | ||
| 97 | + return null; | ||
| 98 | + } | ||
| 99 | + | ||
| 100 | + /** | ||
| 101 | + * Returns object of this class with specified values. | ||
| 102 | + * | ||
| 103 | + * @param ipPrefix ip prefix | ||
| 104 | + * @param length length of ip prefix | ||
| 105 | + * @return object of this class | ||
| 106 | + */ | ||
| 107 | + public static BgpFsDestinationPrefix of(final IpPrefix ipPrefix, final byte length) { | ||
| 108 | + return new BgpFsDestinationPrefix(length, ipPrefix); | ||
| 109 | + } | ||
| 110 | + | ||
| 111 | + @Override | ||
| 112 | + public int compareTo(Object o) { | ||
| 113 | + if (this.equals(o)) { | ||
| 114 | + return 0; | ||
| 115 | + } | ||
| 116 | + | ||
| 117 | + if (o instanceof BgpFsDestinationPrefix) { | ||
| 118 | + BgpFsDestinationPrefix that = (BgpFsDestinationPrefix) o; | ||
| 119 | + | ||
| 120 | + if (this.ipPrefix().prefixLength() == that.ipPrefix().prefixLength()) { | ||
| 121 | + ByteBuffer value1 = ByteBuffer.wrap(this.ipPrefix.address().toOctets()); | ||
| 122 | + ByteBuffer value2 = ByteBuffer.wrap(that.ipPrefix.address().toOctets()); | ||
| 123 | + return value1.compareTo(value2); | ||
| 124 | + } | ||
| 125 | + | ||
| 126 | + if (this.ipPrefix().prefixLength() > that.ipPrefix().prefixLength()) { | ||
| 127 | + return 1; | ||
| 128 | + } else if (this.ipPrefix().prefixLength() < that.ipPrefix().prefixLength()) { | ||
| 129 | + return -1; | ||
| 130 | + } | ||
| 131 | + } | ||
| 132 | + return 1; | ||
| 133 | + } | ||
| 134 | + | ||
| 135 | + @Override | ||
| 136 | + public String toString() { | ||
| 137 | + return MoreObjects.toStringHelper(getClass()) | ||
| 138 | + .add("FLOW_SPEC_TYPE", FLOW_SPEC_TYPE) | ||
| 139 | + .add("length", length) | ||
| 140 | + .add("ipPrefix", ipPrefix).toString(); | ||
| 141 | + } | ||
| 142 | +} |
| 1 | +/* | ||
| 2 | + * Copyright 2016 Open Networking Laboratory | ||
| 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.bgpio.types; | ||
| 17 | + | ||
| 18 | +import java.util.Objects; | ||
| 19 | +import java.util.List; | ||
| 20 | +import org.jboss.netty.buffer.ChannelBuffer; | ||
| 21 | +import org.onosproject.bgpio.exceptions.BgpParseException; | ||
| 22 | +import org.onosproject.bgpio.util.Constants; | ||
| 23 | +import com.google.common.base.MoreObjects; | ||
| 24 | + | ||
| 25 | +/** | ||
| 26 | + * Provides implementation of BGP flow specification component. | ||
| 27 | + */ | ||
| 28 | +public class BgpFsDscpValue implements BgpValueType { | ||
| 29 | + | ||
| 30 | + public static final byte FLOW_SPEC_TYPE = Constants.BGP_FLOWSPEC_DSCP; | ||
| 31 | + private List<BgpFsOperatorValue> operatorValue; | ||
| 32 | + | ||
| 33 | + /** | ||
| 34 | + * Constructor to initialize the value. | ||
| 35 | + * | ||
| 36 | + * @param operatorValue list of operator and value | ||
| 37 | + */ | ||
| 38 | + public BgpFsDscpValue(List<BgpFsOperatorValue> operatorValue) { | ||
| 39 | + this.operatorValue = operatorValue; | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + @Override | ||
| 43 | + public short getType() { | ||
| 44 | + return this.FLOW_SPEC_TYPE; | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + @Override | ||
| 48 | + public int hashCode() { | ||
| 49 | + return Objects.hash(operatorValue); | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + @Override | ||
| 53 | + public boolean equals(Object obj) { | ||
| 54 | + if (this == obj) { | ||
| 55 | + return true; | ||
| 56 | + } | ||
| 57 | + if (obj instanceof BgpFsDscpValue) { | ||
| 58 | + BgpFsDscpValue other = (BgpFsDscpValue) obj; | ||
| 59 | + return this.operatorValue.equals(other.operatorValue); | ||
| 60 | + } | ||
| 61 | + return false; | ||
| 62 | + } | ||
| 63 | + | ||
| 64 | + @Override | ||
| 65 | + public int write(ChannelBuffer cb) { | ||
| 66 | + int iLenStartIndex = cb.writerIndex(); | ||
| 67 | + | ||
| 68 | + cb.writeByte(FLOW_SPEC_TYPE); | ||
| 69 | + | ||
| 70 | + for (BgpFsOperatorValue fsOperVal : operatorValue) { | ||
| 71 | + cb.writeByte(fsOperVal.option()); | ||
| 72 | + cb.writeBytes(fsOperVal.value()); | ||
| 73 | + } | ||
| 74 | + | ||
| 75 | + return cb.writerIndex() - iLenStartIndex; | ||
| 76 | + } | ||
| 77 | + | ||
| 78 | + /** | ||
| 79 | + * Reads the channel buffer and returns object. | ||
| 80 | + * | ||
| 81 | + * @param cb channelBuffer | ||
| 82 | + * @param type address type | ||
| 83 | + * @return object of flow spec DSCP value | ||
| 84 | + * @throws BgpParseException while parsing BgpFsDscpValue | ||
| 85 | + */ | ||
| 86 | + public static BgpFsDscpValue read(ChannelBuffer cb, short type) throws BgpParseException { | ||
| 87 | + return null; | ||
| 88 | + } | ||
| 89 | + | ||
| 90 | + @Override | ||
| 91 | + public String toString() { | ||
| 92 | + return MoreObjects.toStringHelper(getClass()) | ||
| 93 | + .add("FLOW_SPEC_TYPE", FLOW_SPEC_TYPE) | ||
| 94 | + .add("operatorValue", operatorValue).toString(); | ||
| 95 | + } | ||
| 96 | + | ||
| 97 | + @Override | ||
| 98 | + public int compareTo(Object o) { | ||
| 99 | + // TODO Auto-generated method stub | ||
| 100 | + return 0; | ||
| 101 | + } | ||
| 102 | +} |
| 1 | +/* | ||
| 2 | + * Copyright 2016 Open Networking Laboratory | ||
| 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.bgpio.types; | ||
| 17 | + | ||
| 18 | +import java.util.Objects; | ||
| 19 | +import java.util.List; | ||
| 20 | +import org.jboss.netty.buffer.ChannelBuffer; | ||
| 21 | +import org.onosproject.bgpio.exceptions.BgpParseException; | ||
| 22 | +import org.onosproject.bgpio.util.Constants; | ||
| 23 | + | ||
| 24 | +import com.google.common.base.MoreObjects; | ||
| 25 | + | ||
| 26 | +/** | ||
| 27 | + * Provides implementation of BGP flow specification component. | ||
| 28 | + */ | ||
| 29 | +public class BgpFsFragment implements BgpValueType { | ||
| 30 | + public static final byte FLOW_SPEC_TYPE = Constants.BGP_FLOWSPEC_FRAGMENT; | ||
| 31 | + private List<BgpFsOperatorValue> operatorValue; | ||
| 32 | + | ||
| 33 | + /** | ||
| 34 | + * Constructor to initialize the value. | ||
| 35 | + * | ||
| 36 | + * @param operatorValue list of operator and value | ||
| 37 | + */ | ||
| 38 | + public BgpFsFragment(List<BgpFsOperatorValue> operatorValue) { | ||
| 39 | + this.operatorValue = operatorValue; | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + @Override | ||
| 43 | + public short getType() { | ||
| 44 | + return this.FLOW_SPEC_TYPE; | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + @Override | ||
| 48 | + public int hashCode() { | ||
| 49 | + return Objects.hash(operatorValue); | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + @Override | ||
| 53 | + public boolean equals(Object obj) { | ||
| 54 | + if (this == obj) { | ||
| 55 | + return true; | ||
| 56 | + } | ||
| 57 | + if (obj instanceof BgpFsFragment) { | ||
| 58 | + BgpFsFragment other = (BgpFsFragment) obj; | ||
| 59 | + return this.operatorValue.equals(other.operatorValue); | ||
| 60 | + } | ||
| 61 | + return false; | ||
| 62 | + } | ||
| 63 | + | ||
| 64 | + @Override | ||
| 65 | + public int write(ChannelBuffer cb) { | ||
| 66 | + int iLenStartIndex = cb.writerIndex(); | ||
| 67 | + | ||
| 68 | + cb.writeByte(FLOW_SPEC_TYPE); | ||
| 69 | + | ||
| 70 | + for (BgpFsOperatorValue fsOperVal : operatorValue) { | ||
| 71 | + cb.writeByte(fsOperVal.option()); | ||
| 72 | + cb.writeBytes(fsOperVal.value()); | ||
| 73 | + } | ||
| 74 | + | ||
| 75 | + return cb.writerIndex() - iLenStartIndex; | ||
| 76 | + } | ||
| 77 | + | ||
| 78 | + /** | ||
| 79 | + * Reads the channel buffer and returns object. | ||
| 80 | + * | ||
| 81 | + * @param cb channelBuffer | ||
| 82 | + * @param type address type | ||
| 83 | + * @return object of flow spec fragment | ||
| 84 | + * @throws BgpParseException while parsing BgpFsFragment | ||
| 85 | + */ | ||
| 86 | + public static BgpFsFragment read(ChannelBuffer cb, short type) throws BgpParseException { | ||
| 87 | + return null; | ||
| 88 | + } | ||
| 89 | + | ||
| 90 | + @Override | ||
| 91 | + public String toString() { | ||
| 92 | + return MoreObjects.toStringHelper(getClass()) | ||
| 93 | + .add("FLOW_SPEC_TYPE", FLOW_SPEC_TYPE) | ||
| 94 | + .add("operatorValue", operatorValue).toString(); | ||
| 95 | + } | ||
| 96 | + | ||
| 97 | + @Override | ||
| 98 | + public int compareTo(Object o) { | ||
| 99 | + // TODO Auto-generated method stub | ||
| 100 | + return 0; | ||
| 101 | + } | ||
| 102 | +} |
protocols/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/BgpFsDestinationPortNumTest.java
0 → 100644
| 1 | +/* | ||
| 2 | + * Copyright 2016 Open Networking Laboratory | ||
| 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.bgpio.types; | ||
| 17 | + | ||
| 18 | +import java.util.ArrayList; | ||
| 19 | +import java.util.List; | ||
| 20 | + | ||
| 21 | +import org.junit.Test; | ||
| 22 | + | ||
| 23 | +import com.google.common.testing.EqualsTester; | ||
| 24 | + | ||
| 25 | +/** | ||
| 26 | + * Test for destination port number flow specification component. | ||
| 27 | + */ | ||
| 28 | +public class BgpFsDestinationPortNumTest { | ||
| 29 | + List<BgpFsOperatorValue> operatorValue1 = new ArrayList<>(); | ||
| 30 | + List<BgpFsOperatorValue> operatorValue2 = new ArrayList<>(); | ||
| 31 | + | ||
| 32 | + @Test | ||
| 33 | + public void testEquality() { | ||
| 34 | + operatorValue1.add(new BgpFsOperatorValue((byte) 1, new byte[100])); | ||
| 35 | + operatorValue1.add(new BgpFsOperatorValue((byte) 1, new byte[100])); | ||
| 36 | + operatorValue2.add(new BgpFsOperatorValue((byte) 2, new byte[100])); | ||
| 37 | + operatorValue2.add(new BgpFsOperatorValue((byte) 1, new byte[100])); | ||
| 38 | + | ||
| 39 | + BgpFsDestinationPortNum tlv1 = new BgpFsDestinationPortNum(operatorValue1); | ||
| 40 | + BgpFsDestinationPortNum sameAsTlv1 = new BgpFsDestinationPortNum(operatorValue1); | ||
| 41 | + BgpFsDestinationPortNum tlv2 = new BgpFsDestinationPortNum(operatorValue2); | ||
| 42 | + | ||
| 43 | + new EqualsTester() | ||
| 44 | + .addEqualityGroup(tlv1, sameAsTlv1) | ||
| 45 | + .addEqualityGroup(tlv2) | ||
| 46 | + .testEquals(); | ||
| 47 | + } | ||
| 48 | +} |
protocols/bgp/bgpio/src/test/java/org/onosproject/bgpio/types/BgpFsDestinationPrefixTest.java
0 → 100644
| 1 | +/* | ||
| 2 | + * Copyright 2016 Open Networking Laboratory | ||
| 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.bgpio.types; | ||
| 17 | + | ||
| 18 | +import org.junit.Test; | ||
| 19 | +import org.onlab.packet.IpAddress; | ||
| 20 | +import org.onlab.packet.IpPrefix; | ||
| 21 | +import com.google.common.testing.EqualsTester; | ||
| 22 | + | ||
| 23 | +/** | ||
| 24 | + * Test for destination prefix flow specification component. | ||
| 25 | + */ | ||
| 26 | +public class BgpFsDestinationPrefixTest { | ||
| 27 | + private final byte length = 4; | ||
| 28 | + | ||
| 29 | + private final IpPrefix prefix = IpPrefix.valueOf(IpAddress.valueOf("10.0.1.1"), 32); | ||
| 30 | + | ||
| 31 | + private final byte length2 = 4; | ||
| 32 | + private final IpPrefix prefix2 = IpPrefix.valueOf(IpAddress.valueOf("10.0.1.2"), 32); | ||
| 33 | + | ||
| 34 | + private final BgpFsDestinationPrefix tlv1 = new BgpFsDestinationPrefix(length, prefix); | ||
| 35 | + private final BgpFsDestinationPrefix sameAsTlv1 = new BgpFsDestinationPrefix(length, prefix); | ||
| 36 | + private final BgpFsDestinationPrefix tlv2 = new BgpFsDestinationPrefix(length2, prefix2); | ||
| 37 | + | ||
| 38 | + @Test | ||
| 39 | + public void testEquality() { | ||
| 40 | + new EqualsTester() | ||
| 41 | + .addEqualityGroup(tlv1, sameAsTlv1) | ||
| 42 | + .addEqualityGroup(tlv2) | ||
| 43 | + .testEquals(); | ||
| 44 | + } | ||
| 45 | +} |
| 1 | +/* | ||
| 2 | + * Copyright 2016 Open Networking Laboratory | ||
| 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.bgpio.types; | ||
| 17 | + | ||
| 18 | +import java.util.ArrayList; | ||
| 19 | +import java.util.List; | ||
| 20 | + | ||
| 21 | +import org.junit.Test; | ||
| 22 | + | ||
| 23 | +import com.google.common.testing.EqualsTester; | ||
| 24 | + | ||
| 25 | +/** | ||
| 26 | + * Test for DSCP value flow specification component. | ||
| 27 | + */ | ||
| 28 | +public class BgpFsDscpValueTest { | ||
| 29 | + List<BgpFsOperatorValue> operatorValue1 = new ArrayList<>(); | ||
| 30 | + List<BgpFsOperatorValue> operatorValue2 = new ArrayList<>(); | ||
| 31 | + | ||
| 32 | + @Test | ||
| 33 | + public void testEquality() { | ||
| 34 | + operatorValue1.add(new BgpFsOperatorValue((byte) 1, new byte[100])); | ||
| 35 | + operatorValue1.add(new BgpFsOperatorValue((byte) 1, new byte[100])); | ||
| 36 | + operatorValue2.add(new BgpFsOperatorValue((byte) 2, new byte[100])); | ||
| 37 | + operatorValue2.add(new BgpFsOperatorValue((byte) 1, new byte[100])); | ||
| 38 | + | ||
| 39 | + BgpFsDscpValue tlv1 = new BgpFsDscpValue(operatorValue1); | ||
| 40 | + BgpFsDscpValue sameAsTlv1 = new BgpFsDscpValue(operatorValue1); | ||
| 41 | + BgpFsDscpValue tlv2 = new BgpFsDscpValue(operatorValue2); | ||
| 42 | + | ||
| 43 | + new EqualsTester() | ||
| 44 | + .addEqualityGroup(tlv1, sameAsTlv1) | ||
| 45 | + .addEqualityGroup(tlv2) | ||
| 46 | + .testEquals(); | ||
| 47 | + } | ||
| 48 | +} |
| 1 | +/* | ||
| 2 | + * Copyright 2016 Open Networking Laboratory | ||
| 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.bgpio.types; | ||
| 17 | + | ||
| 18 | +import java.util.ArrayList; | ||
| 19 | +import java.util.List; | ||
| 20 | + | ||
| 21 | +import org.junit.Test; | ||
| 22 | + | ||
| 23 | +import com.google.common.testing.EqualsTester; | ||
| 24 | + | ||
| 25 | +/** | ||
| 26 | + * Test for fragment flow specification component. | ||
| 27 | + */ | ||
| 28 | +public class BgpFsFragmentTest { | ||
| 29 | + List<BgpFsOperatorValue> operatorValue1 = new ArrayList<>(); | ||
| 30 | + List<BgpFsOperatorValue> operatorValue2 = new ArrayList<>(); | ||
| 31 | + | ||
| 32 | + @Test | ||
| 33 | + public void testEquality() { | ||
| 34 | + operatorValue1.add(new BgpFsOperatorValue((byte) 1, new byte[100])); | ||
| 35 | + operatorValue1.add(new BgpFsOperatorValue((byte) 1, new byte[100])); | ||
| 36 | + operatorValue2.add(new BgpFsOperatorValue((byte) 2, new byte[100])); | ||
| 37 | + operatorValue2.add(new BgpFsOperatorValue((byte) 1, new byte[100])); | ||
| 38 | + | ||
| 39 | + BgpFsFragment tlv1 = new BgpFsFragment(operatorValue1); | ||
| 40 | + BgpFsFragment sameAsTlv1 = new BgpFsFragment(operatorValue1); | ||
| 41 | + BgpFsFragment tlv2 = new BgpFsFragment(operatorValue2); | ||
| 42 | + | ||
| 43 | + new EqualsTester() | ||
| 44 | + .addEqualityGroup(tlv1, sameAsTlv1) | ||
| 45 | + .addEqualityGroup(tlv2) | ||
| 46 | + .testEquals(); | ||
| 47 | + } | ||
| 48 | +} |
-
Please register or login to post a comment