Skip to content

Commit

Permalink
Merge pull request #84 from cne/hardening/bugfix_1_2
Browse files Browse the repository at this point in the history
Hardening/bugfix 1 2
  • Loading branch information
oscargdd committed Feb 25, 2016
2 parents 58b0f24 + 909d3a7 commit 2535fc5
Show file tree
Hide file tree
Showing 84 changed files with 2,819 additions and 926 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
v1.2.1
- Make JUnit tests compatible with java 1.7
- JUnit tests for PCEP Constructs
- Added coding of REQ_ADAP_CAP from draft-ietf-pce-gmpls-pcep-extensions-11
- Deleted old SRERO objects (no longer used)
- Added encoding of REQ_MISSING_TLV
- BGP-LS Path Attribute: Next Hop Address IPv4 encoding added
- Update to https://tools.ietf.org/html/draft-ietf-pce-segment-routing-06
- Bugfixes
v1.2
- Added JUnit tests for PCEP (still to be fully completed)
Expand Down
32 changes: 30 additions & 2 deletions src/main/java/es/tid/bgp/bgp4/objects/BGP4Object.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package es.tid.bgp.bgp4.objects;

import java.util.Arrays;

import es.tid.bgp.bgp4.BGP4Element;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -15,13 +18,38 @@ public abstract class BGP4Object implements BGP4Element {
public byte[] getBytes() {
return bytes;
}
public void setBytes(byte[] bytes) {
protected void setBytes(byte[] bytes) {
this.bytes = bytes;
}
public int getLength() {
return length;
}
public void setLength(int length) {
protected void setLength(int length) {
this.length = length;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + Arrays.hashCode(bytes);
result = prime * result + length;
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
BGP4Object other = (BGP4Object) obj;
if (!Arrays.equals(bytes, other.bytes))
return false;
if (length != other.length)
return false;
return true;
}


}
33 changes: 31 additions & 2 deletions src/main/java/es/tid/bgp/bgp4/update/fields/LinkStateNLRI.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public int getNLRIType() {
}


public void setNLRIType(int nLRIType) {
protected void setNLRIType(int nLRIType) {
NLRIType = nLRIType;
}

Expand All @@ -91,7 +91,7 @@ public int getTotalNLRILength() {
}


public void setTotalNLRILength(int totalNLRILength) {
protected void setTotalNLRILength(int totalNLRILength) {
TotalNLRILength = totalNLRILength;
}

Expand All @@ -111,4 +111,33 @@ public static int getNLRIType(byte[] bytes, int offset){

public abstract void encode();


@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + NLRIType;
result = prime * result + TotalNLRILength;
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;
LinkStateNLRI other = (LinkStateNLRI) obj;
if (NLRIType != other.NLRIType)
return false;
if (TotalNLRILength != other.TotalNLRILength)
return false;
return true;
}



}
48 changes: 46 additions & 2 deletions src/main/java/es/tid/bgp/bgp4/update/fields/PathAttribute.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package es.tid.bgp.bgp4.update.fields;

import es.tid.bgp.bgp4.objects.BGP4Object;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -107,7 +108,7 @@ public void encodeHeader(){

}

public void setPathAttributeLength(int pal){
protected void setPathAttributeLength(int pal){
this.pathAttributeLength= pal;
if (pathAttributeLength>255){
this.mandatoryLength=4;
Expand Down Expand Up @@ -165,11 +166,53 @@ public int getTypeCode() {
}


public void setTypeCode(int typeCode) {
protected void setTypeCode(int typeCode) {
this.typeCode = typeCode;
}


@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + (extendedLengthBit ? 1231 : 1237);
result = prime * result + mandatoryLength;
result = prime * result + (optionalBit ? 1231 : 1237);
result = prime * result + (partialBit ? 1231 : 1237);
result = prime * result + pathAttributeLength;
result = prime * result + (transitiveBit ? 1231 : 1237);
result = prime * result + typeCode;
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;
PathAttribute other = (PathAttribute) obj;
if (extendedLengthBit != other.extendedLengthBit)
return false;
if (mandatoryLength != other.mandatoryLength)
return false;
if (optionalBit != other.optionalBit)
return false;
if (partialBit != other.partialBit)
return false;
if (pathAttributeLength != other.pathAttributeLength)
return false;
if (transitiveBit != other.transitiveBit)
return false;
if (typeCode != other.typeCode)
return false;
return true;
}



// public String toString() {
// return "[typeCode=" + typeCode + ", optionalBit="
Expand All @@ -179,6 +222,7 @@ public void setTypeCode(int typeCode) {
// }





}
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,34 @@ public String toString(){

return text;
}

@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((lsNLRI == null) ? 0 : lsNLRI.hashCode());
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;
BGP_LS_MP_Reach_Attribute other = (BGP_LS_MP_Reach_Attribute) obj;
if (lsNLRI == null) {
if (other.lsNLRI != null)
return false;
} else if (!lsNLRI.equals(other.lsNLRI))
return false;
return true;
}





}
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,19 @@ public MP_Reach_Attribute(byte [] bytes, int offset){
this.addressFamilyIdentifier=((this.bytes[offset2]&0xFF)<<8) | (this.bytes[offset2+1]&0xFF);
this.subsequentAddressFamilyIdentifier = (this.bytes[offset2+2]&0xFF);
this.nextHopLength= (this.bytes[offset2+3]&0xFF);
//FIXME: RELLENAR NEXT HOP NETWORK ADDRESS
// System.arraycopy(bytes, offset+4, this.networkAddressofNextHop, 0, lengthofNextHopNetworkAddress);*/
byte[] bytos = new byte[nextHopLength];

System.arraycopy(bytes, offset2+4, bytos, 0, this.nextHopLength);
if (this.nextHopLength==4){
try {
this.nextHop=Inet4Address.getByAddress(bytos);
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

//FIXME: ADD IPv6


}
Expand All @@ -184,13 +194,9 @@ protected void encodeMP_Reach_Header(){
this.bytes[offset+2]=(byte)(this.subsequentAddressFamilyIdentifier&0xFF);
this.bytes[offset+3]=(byte)this.getNextHopLength();
offset=offset+4;
//FIXME: 0.0.0.0 Por defecto
//FIXME: Complete IPv6
if (this.nextHopLength==4){
this.bytes[offset]=0;
this.bytes[offset+1]=0;
this.bytes[offset+2]=0;
this.bytes[offset+3]=0;

System.arraycopy(this.nextHop.getAddress(), 0, this.bytes, offset, 4);
}
offset=offset+this.getNextHopLength();
this.bytes[offset]=0;
Expand All @@ -206,15 +212,15 @@ public int getAddressFamilyIdentifier() {
return addressFamilyIdentifier;
}

public void setAddressFamilyIdentifier(int addressFamilyIdentifier) {
protected void setAddressFamilyIdentifier(int addressFamilyIdentifier) {
this.addressFamilyIdentifier = addressFamilyIdentifier;
}

public int getSubsequentAddressFamilyIdentifier() {
return subsequentAddressFamilyIdentifier;
}

public void setSubsequentAddressFamilyIdentifier(
protected void setSubsequentAddressFamilyIdentifier(
int subsequentAddressFamilyIdentifier) {
this.subsequentAddressFamilyIdentifier = subsequentAddressFamilyIdentifier;
}
Expand Down Expand Up @@ -265,4 +271,40 @@ public String toString(){
return "mp";
}

@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + addressFamilyIdentifier;
result = prime * result + ((nextHop == null) ? 0 : nextHop.hashCode());
result = prime * result + nextHopLength;
result = prime * result + subsequentAddressFamilyIdentifier;
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;
MP_Reach_Attribute other = (MP_Reach_Attribute) obj;
if (addressFamilyIdentifier != other.addressFamilyIdentifier)
return false;
if (nextHop == null) {
if (other.nextHop != null)
return false;
} else if (!nextHop.equals(other.nextHop))
return false;
if (nextHopLength != other.nextHopLength)
return false;
if (subsequentAddressFamilyIdentifier != other.subsequentAddressFamilyIdentifier)
return false;
return true;
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ public class IGPRouterIDNodeDescriptorSubTLV extends NodeDescriptorsSubTLV {


private int igp_router_id_type;//initialized to 2--> rest not implemented yet
int length;

private Inet4Address ipv4Address_ospf = null;
private Inet4Address ipv4Address_ospf_dr_address = null;
Expand All @@ -42,7 +41,7 @@ public IGPRouterIDNodeDescriptorSubTLV(byte [] bytes, int offset){
}

private void decode() {
length = this.getSubTLVValueLength();
int length = this.getSubTLVValueLength();
int offset = 4; //SubTLV header
switch(length){
case 4:
Expand Down Expand Up @@ -109,7 +108,7 @@ public void encode() {
switch(igp_router_id_type){
case IGP_ROUTER_ID_TYPE_OSPF_NON_PSEUDO:
log.debug("Encoding IGP Node ID Type: OSPF NON PSEUDO");
this.length = 4;
int length = 4;
this.setSubTLVValueLength(length);
this.subtlv_bytes=new byte[this.getTotalSubTLVLength()];
encodeHeader();
Expand Down Expand Up @@ -175,6 +174,7 @@ public void setPSN_IDENT(int pSN_IDENT) {
}

public String toString() {
int length=this.getSubTLVValueLength();
switch(length){
case 4:
return "IGP_ROUTER_ID [type=" + this.getIGP_router_id_type() + ", ID_OSPF_NON_PSEUDO="
Expand All @@ -193,4 +193,20 @@ public String toString() {
}
}

public int getIgp_router_id_type() {
return igp_router_id_type;
}

public void setIgp_router_id_type(int igp_router_id_type) {
this.igp_router_id_type = igp_router_id_type;
}

public Inet4Address getIpv4Address_ospf() {
return ipv4Address_ospf;
}

public void setIpv4Address_ospf(Inet4Address ipv4Address_ospf) {
this.ipv4Address_ospf = ipv4Address_ospf;
}

}
Loading

0 comments on commit 2535fc5

Please sign in to comment.