From 29f818fcdaae2c1399e93ba08fa124a7bfc8aaa9 Mon Sep 17 00:00:00 2001 From: idb0177 Date: Fri, 25 Oct 2024 09:44:23 +0200 Subject: [PATCH] Include PathProtectionAssociationTLV class Fix ObjectParameters --- .../pce/pcep/objects/ObjectParameters.java | 2 +- .../tlvs/PathProtectionAssociationTLV.java | 100 ++++++++++++++++++ 2 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 src/main/java/es/tid/pce/pcep/objects/tlvs/PathProtectionAssociationTLV.java diff --git a/src/main/java/es/tid/pce/pcep/objects/ObjectParameters.java b/src/main/java/es/tid/pce/pcep/objects/ObjectParameters.java index 8a48bac..e042ba3 100644 --- a/src/main/java/es/tid/pce/pcep/objects/ObjectParameters.java +++ b/src/main/java/es/tid/pce/pcep/objects/ObjectParameters.java @@ -932,7 +932,7 @@ public final class ObjectParameters { /** * 38 Path Protection Association Group TLV [RFC8745] */ - public static final int PCEP_TLV_PATH_PROT_ASSOCIATION_GROUP=39; + public static final int PCEP_TLV_PATH_PROT_ASSOCIATION_GROUP=38; /** * 39 IPV4-ADDRESS [RFC8779, Section 2.5.2.1] diff --git a/src/main/java/es/tid/pce/pcep/objects/tlvs/PathProtectionAssociationTLV.java b/src/main/java/es/tid/pce/pcep/objects/tlvs/PathProtectionAssociationTLV.java new file mode 100644 index 0000000..2ea27f8 --- /dev/null +++ b/src/main/java/es/tid/pce/pcep/objects/tlvs/PathProtectionAssociationTLV.java @@ -0,0 +1,100 @@ +package es.tid.pce.pcep.objects.tlvs; + + +import java.util.Objects; + +import es.tid.pce.pcep.objects.MalformedPCEPObjectException; +import es.tid.pce.pcep.objects.ObjectParameters; +import es.tid.protocol.commons.ByteHandler; + +public class PathProtectionAssociationTLV extends PCEPTLV{ + /* + 0 1 2 3 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Type = 39 | Length = 4 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Data | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + + Figure 1: Path Protection Association TLV Format + */ + + private long data; + + + public PathProtectionAssociationTLV() { + this.setTLVType(ObjectParameters.PCEP_TLV_PATH_PROT_ASSOCIATION_GROUP); + } + + public PathProtectionAssociationTLV(byte[] bytes, int offset) throws MalformedPCEPObjectException + { + super(bytes,offset); + decode(); + } + + public long getData() { + return data; + } + + public void setData(long data) { + this.data = data; + } + + @Override + public void encode() { + log.debug("Encoding PathProtectionAssociation TLV"); + this.setTLVValueLength(4); + + this.tlv_bytes = new byte[this.getTotalTLVLength()]; + this.encodeHeader(); + int offset = 4; + + ByteHandler.encode4bytesLong(data, this.tlv_bytes, offset); + + + } + + public void decode() throws MalformedPCEPObjectException { + log.debug("Decoding SymbolicPathName TLV"); + int offset=4;//Position of the next subobject + try { + this.data = ByteHandler.decode4bytesLong(this.tlv_bytes, offset); + }catch (Exception e) + { + log.error("Exception occurred, Possibly TLV size is not what expected"); + throw new MalformedPCEPObjectException(); + } + + + + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + Objects.hash(data); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!super.equals(obj)) + return false; + if (getClass() != obj.getClass()) + return false; + PathProtectionAssociationTLV other = (PathProtectionAssociationTLV) obj; + return data == other.data; + } + + @Override + public String toString() { + return "PathProtectionAssociationTLV [data=" + data + "]"; + } + + + +}