description "CLOSE Object";
reference "https://tools.ietf.org/html/rfc5440#section-7.17";
- uses object;
-
- leaf reason {
- type uint8;
- mandatory true;
- }
-
- container tlvs {
-
+ container c-close {
+ uses object;
+
+ leaf reason {
+ type uint8;
+ mandatory true;
+ }
+
+ container tlvs {
+
+ }
}
}
uses message-header;
- container c-close {
- uses close-object;
- }
+ uses close-object;
}
}
private final static int COMMON_OBJECT_HEADER_LENGTH = 4;
private final static int OC_F_LENGTH = 1;
- private final static int OT_FLAGS_MF_LENGTH = 1; // multi-field
+ private final static int OT_FLAGS_MF_LENGTH = 1;
private final static int OBJ_LENGTH_F_LENGTH = 2;
private final static int OC_F_OFFSET = 0;
final byte[] retBytes = new byte[COMMON_OBJECT_HEADER_LENGTH + valueBytes.length];
// objClass
- retBytes[OC_F_OFFSET] = (byte) serializer.getObjectClass();
+ retBytes[OC_F_OFFSET] = UnsignedBytes.checkedCast(serializer.getObjectClass());
// objType_flags multi-field
- retBytes[OT_FLAGS_MF_OFFSET] = (byte) (serializer.getObjectType() << (Byte.SIZE - OT_SF_LENGTH));
+ retBytes[OT_FLAGS_MF_OFFSET] = UnsignedBytes.checkedCast(serializer.getObjectType() << (Byte.SIZE - OT_SF_LENGTH));
if (object.isProcessingRule()) {
retBytes[OT_FLAGS_MF_OFFSET] |= 1 << Byte.SIZE - (P_FLAG_OFFSET) - 1;
}
}
// objLength
- System.arraycopy(ByteArray.intToBytes(valueBytes.length), Integer.SIZE / Byte.SIZE - OBJ_LENGTH_F_LENGTH, retBytes,
- OBJ_LENGTH_F_OFFSET, OBJ_LENGTH_F_LENGTH);
-
- System.arraycopy(valueBytes, 0, retBytes, COMMON_OBJECT_HEADER_LENGTH, valueBytes.length);
+ System.arraycopy(ByteArray.intToBytes(valueBytes.length + COMMON_OBJECT_HEADER_LENGTH), Integer.SIZE / Byte.SIZE
+ - OBJ_LENGTH_F_LENGTH, retBytes, OBJ_LENGTH_F_OFFSET, OBJ_LENGTH_F_LENGTH);
+ ByteArray.copyWhole(valueBytes, retBytes, COMMON_OBJECT_HEADER_LENGTH);
return retBytes;
}
+ COMMON_OBJECT_HEADER_LENGTH + ".");
}
- final int objClass = ByteArray.bytesToInt(Arrays.copyOfRange(bytes, OC_F_OFFSET, OC_F_OFFSET + OC_F_LENGTH));
+ final int objClass = UnsignedBytes.toInt(bytes[OC_F_OFFSET]);
final int objType = UnsignedBytes.toInt(ByteArray.copyBitsRange(bytes[OT_FLAGS_MF_OFFSET], OT_SF_OFFSET, OT_SF_LENGTH));
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.BandwidthObject;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ClasstypeObject;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.CloseMessage;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.CloseObject;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.EndpointsObject;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ExcludeRouteObject;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ExplicitRouteObject;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.RpObject;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.SrpObject;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.SvecObject;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.object.CClose;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.explicit.route.object.subobjects.subobject.type.PathKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.db.version.tlv.LspDbVersion;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.error.code.tlv.LspErrorCode;
context.registerObjectSerializer(NotificationObject.class, new PCEPNotificationObjectParser(tlvReg));
context.registerObjectSerializer(PcepErrorObject.class, new PCEPErrorObjectParser(tlvReg));
context.registerObjectSerializer(LoadBalancingObject.class, new PCEPLoadBalancingObjectParser(tlvReg));
- context.registerObjectSerializer(CloseObject.class, new PCEPCloseObjectParser(tlvReg));
+ context.registerObjectSerializer(CClose.class, new PCEPCloseObjectParser(tlvReg));
context.registerObjectSerializer(PathKeyObject.class, new PCEPPathKeyObjectParser(eroSubReg));
context.registerObjectSerializer(OfObject.class, new PCEPObjectiveFunctionObjectParser(tlvReg));
context.registerObjectSerializer(ClasstypeObject.class, new PCEPClassTypeObjectParser(tlvReg));
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OpenMessage;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OpenObject;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.message.CCloseMessageBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.message.c.close.message.CCloseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.object.CCloseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.keepalive.message.KeepaliveMessageBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.Tlvs;
import org.slf4j.Logger;
/**
* Sends message to serialization.
- *
+ *
* @param msg to be sent
*/
@Override
@Override
public Tlvs getRemoteTlvs() {
- return remoteOpen.getTlvs();
+ return this.remoteOpen.getTlvs();
}
@Override
/**
* Sends PCEP Error Message with one PCEPError and Open Object.
- *
+ *
* @param value
* @param open
*/
* sent (CAPABILITY_NOT_SUPPORTED) and the method checks if the MAX_UNKNOWN_MSG per minute wasn't overstepped.
* Second, any other error occurred that is specified by rfc. In this case, the an error message is generated and
* sent.
- *
+ *
* @param error documented error in RFC5440 or draft
*/
@VisibleForTesting
/**
* Handles incoming message. If the session is up, it notifies the user. The user is notified about every message
* except KeepAlive.
- *
+ *
* @param msg incoming message
*/
@Override
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.message.CCloseMessage;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.message.CCloseMessageBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.message.c.close.message.CClose;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.object.CClose;
/**
- * Parser for {@link org.opendaylight.protocol.pcep.message.PCEPCloseMessage PCEPCloseMessage}
+ * Parser for {@link CloseMessage}
*/
public class PCEPCloseMessageParser extends AbstractMessageParser {
throw new PCEPDeserializerException("Close message doesn't contain CLOSE object.");
}
final List<Object> objs = parseObjects(buffer);
-
return validate(objs);
}
if (objects == null) {
throw new IllegalArgumentException("Passed list can't be null.");
}
-
if (objects.isEmpty() || !(objects.get(0) instanceof CClose)) {
throw new PCEPDeserializerException("Close message doesn't contain CLOSE object.");
}
-
final Object o = objects.get(0);
final CCloseMessage msg = new CCloseMessageBuilder().setCClose((CClose) o).build();
objects.remove(0);
-
if (!objects.isEmpty()) {
throw new PCEPDeserializerException("Unprocessed Objects: " + objects);
}
-
return new CloseBuilder().setCCloseMessage(msg).build();
}
throw new IllegalArgumentException("Wrong instance of Message. Passed instance of " + message.getClass()
+ ". Nedded KeepaliveMessage.");
}
-
buffer.writeBytes(new byte[0]);
}
import org.opendaylight.protocol.pcep.PCEPDocumentedException;
import org.opendaylight.protocol.pcep.spi.TlvHandlerRegistry;
import org.opendaylight.protocol.util.ByteArray;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.CloseObject;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ObjectHeader;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.message.c.close.message.CClose;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.message.c.close.message.CCloseBuilder;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.object.Tlvs;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.object.CClose;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.object.CCloseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.object.c.close.Tlvs;
import com.google.common.primitives.UnsignedBytes;
}
@Override
- public CloseObject parseObject(final ObjectHeader header, final byte[] bytes) throws PCEPDeserializerException, PCEPDocumentedException {
+ public CClose parseObject(final ObjectHeader header, final byte[] bytes) throws PCEPDeserializerException, PCEPDocumentedException {
if (bytes == null) {
throw new IllegalArgumentException("Byte array is mandatory.");
}
@Override
public byte[] serializeObject(final Object object) {
- if (!(object instanceof CloseObject)) {
+ if (!(object instanceof CClose)) {
throw new IllegalArgumentException("Wrong instance of PCEPObject. Passed " + object.getClass() + ". Needed CloseObject.");
}
- final CloseObject obj = (CloseObject) object;
+ final CClose obj = (CClose) object;
final byte[] tlvs = serializeTlvs(obj.getTlvs());
int tlvsLength = 0;
if (tlvs != null) {
ByteArray.copyWhole(tlvs, retBytes, TLVS_OFFSET);
}
- retBytes[REASON_F_OFFSET] = UnsignedBytes.checkedCast(((CClose) obj).getReason());
+ retBytes[REASON_F_OFFSET] = UnsignedBytes.checkedCast(obj.getReason());
return retBytes;
}
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ProtocolVersion;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.RequestId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.SrpIdNumber;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.message.c.close.message.CCloseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.object.CCloseBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.address.family.Ipv4Builder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.endpoints.address.family.Ipv6Builder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.exclude.route.object.Subobjects;
*/
package org.opendaylight.protocol.pcep.impl;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
+
+import java.io.IOException;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.protocol.framework.DeserializerException;
+import org.opendaylight.protocol.framework.DocumentedException;
+import org.opendaylight.protocol.pcep.PCEPDeserializerException;
+import org.opendaylight.protocol.pcep.PCEPDocumentedException;
+import org.opendaylight.protocol.pcep.impl.message.PCEPCloseMessageParser;
+import org.opendaylight.protocol.pcep.impl.message.PCEPKeepAliveMessageParser;
+import org.opendaylight.protocol.pcep.spi.ObjectHandlerRegistry;
+import org.opendaylight.protocol.pcep.spi.pojo.PCEPExtensionProviderContextImpl;
+import org.opendaylight.protocol.util.ByteArray;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.CloseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.message.rev131007.KeepaliveBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.message.CCloseMessageBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.close.object.CCloseBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.keepalive.message.KeepaliveMessageBuilder;
public class PCEPValidatorTest {
+ private ObjectHandlerRegistry objectRegistry;
+
+ @Before
+ public void setUp() throws Exception {
+ this.objectRegistry = PCEPExtensionProviderContextImpl.create().getObjectHandlerRegistry();
+ }
+
// private static final LspaObject lspa = new PCEPLspaObject(0L, 0L, 0L, (short) 0, (short) 0, false, false, false,
// false);
//
// private final PCEPEndPointsObject<IPv4Address> endPoints = new PCEPEndPointsObject<IPv4Address>(this.ip4addr,
// this.ip4addr);
//
- // private static final RawPCEPMessageFactory msgFactory = new RawPCEPMessageFactory();
- //
- // // private final PCEPClassTypeObject classType = new
- // // PCEPClassTypeObject((short) 7);
- // // private final PCEPClassTypeObjectProvider classTypeProvider = new
- // // PCEPClassTypeObjectProvider((short) 7, true);
- //
- // private static List<Message> deserMsg(final String srcFile) throws IOException, DeserializerException,
- // DocumentedException,
- // PCEPDeserializerException {
- // final byte[] bytesFromFile = ByteArray.fileToBytes(srcFile);
- // final RawMessage rawMessage = (RawMessage) msgFactory.parse(bytesFromFile).get(0);
- //
- // return PCEPMessageValidator.getValidator(rawMessage.getMsgType()).validate(rawMessage.getAllObjects());
- // }
//
// @Test
// public void testOpenMessageValidationFromBin() throws IOException, DeserializerException, DocumentedException,
// new LSPStateDBVersionTlv(53))))).toString());
// }
//
- // @Test
- // public void testKeepAliveMessageValidationFromBin() throws IOException, PCEPDeserializerException,
- // PCEPDocumentedException,
- // DeserializerException, DocumentedException {
- // assertEquals(deserMsg("src/test/resources/PCEPKeepAliveMessage1.bin").toString(),
- // asList(new KeepaliveBuilder().setKeepaliveMessage(new KeepaliveMessageBuilder().build()).build()).toString());
- // assertEquals(deserMsg("src/test/resources/Keepalive.1.bin").toString(),
- // asList(new KeepaliveBuilder().setKeepaliveMessage(new KeepaliveMessageBuilder().build()).build()).toString());
- // }
- //
- // @Test
- // @Ignore
- // // FIXME: should be fixed when we remove PCEPObject
- // public void testCloseMsg() throws PCEPDeserializerException, IOException, PCEPDocumentedException,
- // DeserializerException,
- // DocumentedException {
- // assertEquals(
- // deserMsg("src/test/resources/PCEPCloseMessage1.bin"),
- // asList(new CloseBuilder().setCCloseMessage(
- // new CCloseMessageBuilder().setCClose(
- // new CCloseBuilder().setReason(TerminationReason.TooManyUnknownMsg.getShortValue()).build()).build()).build()));
- // assertEquals(
- // deserMsg("src/test/resources/Close.1.bin").toString(),
- // asList(new CloseBuilder().setCCloseMessage(
- // new CCloseMessageBuilder().setCClose(
- // new CCloseBuilder().setReason(TerminationReason.Unknown.getShortValue()).build()).build()).build()));
- // }
- //
+
+ @Test
+ public void testKeepAliveMessageValidationFromBin() throws IOException, PCEPDeserializerException, PCEPDocumentedException,
+ DeserializerException, DocumentedException {
+ final byte[] result = new byte[] { 0, 0, 0, 0 };
+ final PCEPKeepAliveMessageParser parser = new PCEPKeepAliveMessageParser(this.objectRegistry);
+ final KeepaliveBuilder builder = new KeepaliveBuilder().setKeepaliveMessage(new KeepaliveMessageBuilder().build());
+
+ assertEquals(builder.build(), parser.parseMessage(result));
+ final ByteBuf buf = Unpooled.buffer(result.length);
+ parser.serializeMessage(builder.build(), buf);
+ assertArrayEquals(result, buf.array());
+ }
+
+ @Test
+ public void testCloseMsg() throws PCEPDeserializerException, IOException, PCEPDocumentedException, DeserializerException,
+ DocumentedException {
+ final byte[] result = ByteArray.fileToBytes("src/test/resources/PCEPCloseMessage1.bin");
+
+ final PCEPCloseMessageParser parser = new PCEPCloseMessageParser(this.objectRegistry);
+ final CloseBuilder builder = new CloseBuilder().setCCloseMessage(new CCloseMessageBuilder().setCClose(
+ new CCloseBuilder().setIgnore(false).setProcessingRule(false).setReason((short) 5).build()).build());
+
+ assertEquals(builder.build(), parser.parseMessage(result));
+ final ByteBuf buf = Unpooled.buffer(result.length);
+ parser.serializeMessage(builder.build(), buf);
+ assertArrayEquals(result, buf.array());
+ }
// @Test
// public void testRequestMessageValidationFromBin() throws IOException, PCEPDeserializerException,
// PCEPDocumentedException,