Skip to content

Commit

Permalink
Merge pull request #108 from cne/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
oscargdd committed Jun 1, 2016
2 parents df48f27 + 4aaea68 commit 95e705d
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 30 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
v1.3.2
- Hotfix to work with BPGPeer
- Ability to work with multiple NLRIs in the same BGP-LS MP Reach
v.1.3.1
- License is now Apache 2.0
- BPG-LS Tested with Juniper MX routers
Expand Down
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
netphony-network-protocols v1.3.1
netphony-network-protocols v1.3.2
=================================

Repository branch build status:
Expand All @@ -19,15 +19,17 @@ The netphony-network-protocols library is an implementation of four networking p

The protocol library can be easily integrated in any software that needs to interact with other software/devices using these protoocols. The library provides the encoding and decoding from java objects to bit-level. Note that, the state machine and set up of sessions is provided by other components, also available in github.

The PCEP implemnentation has been tested against other PCEP implementations (Telecom Italia Implementation, CTTC Implementation and CNIT Implementation) .
The PCEP implemnentation has been tested against other PCEP implementations (Telecom Italia Implementation, CTTC Implementation and CNIT Implementation) .

The Netphony BGP-LS implementation is known to interoperate with Telecom Italia Implementation, CTTC Implementation and CNIT Implementation. It is listed in the IETF BGP-LS implemenation report https://tools.ietf.org/html/draft-ietf-idr-ls-distribution-impl-04
The Netphony BGP-LS implementation is known to interoperate with Telecom Italia Implementation, CTTC Implementation and CNIT Implementation and Juniper MX routers. It is listed in the IETF BGP-LS implemenation report https://tools.ietf.org/html/draft-ietf-idr-ls-distribution-impl-04

The library is maintained to be up-to-date to the latest version of the internet-drafts/RFCs. **Contributions are highly welcomed.**

Detailed CHANGELOG [click here](CHANGELOG)

## **Latest news**
- Hotfix to work with BPGPeer
- Ability to work with multiple NLRIs in the same BGP-LS MP Reach
- License is now Apache 2.0
- BPG-LS Tested with Juniper MX routers
- Various bugfixes in BGP-LS
Expand All @@ -47,7 +49,7 @@ To build the .jar file and run the tests, clone the repository, go to the main d
<dependency>
<groupId>es.tid.netphony</groupId>
<artifactId>network-protocols</artifactId>
<version>1.3.1</version>
<version>1.3.2</version>
</dependency>
```
Authors keep also a copy of the artifact in maven central to facilitate the deployment. (*) In process
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v1.3.1
v1.3.2
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>es.tid.netphony</groupId>
<artifactId>network-protocols</artifactId>
<version>1.3.1</version>
<version>1.3.2</version>
<packaging>jar</packaging>
<name>Netphony Network Protocols</name>
<description>BGP-LS,OSPF-TE,PCEP and RSVP-TE protocol encodings.</description>
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/es/tid/bgp/bgp4/messages/BGP4Update.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ public void encode()
//Add Path Attributes
for(int i = 0; i < pathAttributes.size(); ++ i)
{

System.arraycopy(pathAttributes.get(i).getBytes(), 0, messageBytes, offset, pathAttributes.get(i).getLength());
offset = offset + pathAttributes.get(i).getLength();
}
Expand Down Expand Up @@ -178,7 +177,6 @@ public void decode()
//Path Attributes Length
totalPathAttibuteLength = ((((int) messageBytes[offset]) << 8) & 0xFF00) | ((int) messageBytes[offset + 1] & 0xFF);
offset = offset + 2;
//QUITAR log.info("OSCAR totalPathAttibuteLength "+totalPathAttibuteLength+" Y offset a "+offset);
if(totalPathAttibuteLength != 0)
{
pathAttributes = new ArrayList<PathAttribute>();
Expand Down Expand Up @@ -230,6 +228,9 @@ public void decode()
offset = offset + attribute_length + mandatory_length;
len = len + attribute_length + mandatory_length;
}
if (offset>=this.getLength()){
return;
}
//NLRI
//if (nlri != null){
int nlri_type = LinkStateNLRI.getNLRIType(messageBytes, offset);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ public AS_Path_Attribute()
//Poner los flags.
this.typeCode = PathAttributesTypeCode.PATH_ATTRIBUTE_TYPECODE_ASPATH;
asPathSegments = new LinkedList<AS_Path_Segment>();
length = mandatoryLength; //Initial length FLAGS + TYPE + LENGTH
}

public AS_Path_Attribute(byte[] bytes, int offset) throws MalformedBGP4ElementException
Expand All @@ -60,15 +59,22 @@ public AS_Path_Attribute(byte[] bytes, int offset) throws MalformedBGP4ElementEx
@Override
public void encode()
{
bytes = new byte[length];
pathAttributeLength = length - mandatoryLength; //Total length minus (FLAGS + TYPE + LENGTH)
encodeHeader();
int offset = 3; //After the header encoding
int path_attribute_length=0;

for(AS_Path_Segment asPathSegment : asPathSegments)
{
asPathSegment.encode();
System.arraycopy(asPathSegment.getBytes(), 0, bytes, offset, asPathSegment.getLength());
offset += asPathSegment.getLength();
path_attribute_length+=asPathSegment.getLength();
}
this.setPathAttributeLength(path_attribute_length);
bytes = new byte[length];
encodeHeader();
int offset = this.mandatoryLength; //After the header encoding
int num_segs=asPathSegments.size();
for(int i=0;i<num_segs;++i)
{
System.arraycopy(asPathSegments.get(i).getBytes(), 0, bytes, offset, asPathSegments.get(i).getLength());
offset += asPathSegments.get(i).getLength();
}

}
Expand All @@ -77,8 +83,8 @@ public void decode() throws MalformedBGP4ElementException
{
if(typeCode != PathAttributesTypeCode.PATH_ATTRIBUTE_TYPECODE_ASPATH)
throw new MalformedBGP4ElementException();

int offset = 3; //1 octet flags, 1 octet type, 1 octet length
int offset = this.mandatoryLength;
while(offset < length)
{
AS_Path_Segment asPathSegment = new AS_Path_Segment(bytes, offset);
Expand All @@ -97,14 +103,17 @@ public int getType()
public void setAsPathSegments(List<AS_Path_Segment> asPathSegments)
{
this.asPathSegments = asPathSegments;
for(AS_Path_Segment asPathSegment : asPathSegments)
length += asPathSegment.getLength();
}

@Override
public String toString()
{
return "AS_PATH [Type=" + typeCode + " Length=" + length + " NumberOfAsPathSegments=" + asPathSegments.size() + "]";
String ret="";
ret+="AS_PATH [Type=" + typeCode + " Length=" + length + " NumberOfAsPathSegments=" + asPathSegments.size() + "]";
for (int i=0; i<asPathSegments.size();++i){
ret+=asPathSegments.toString();
}
return ret;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ public class AS_Path_Segment implements BGP4Element

public AS_Path_Segment()
{
length = 2;
type = PathAttributesTypeCode.PATH_ATTRIBUTE_ASPATH_AS_SEQUENCE;
} //Type and number, and nothing else;

public AS_Path_Segment(byte[] bytes, int offset) throws MalformedBGP4ElementException
{

this.type = (int) bytes[offset] & 0xFF;
if(this.type != PathAttributesTypeCode.PATH_ATTRIBUTE_ASPATH_AS_SEQUENCE && this.type != PathAttributesTypeCode.PATH_ATTRIBUTE_ASPATH_AS_SET)
throw new MalformedBGP4ElementException();
Expand All @@ -75,6 +75,8 @@ public AS_Path_Segment(byte[] bytes, int offset) throws MalformedBGP4ElementExce
@Override
public void encode()
{
this.length = 2 + numberOfSegments * 2;

int offset = 0;
bytes = new byte[this.length];
bytes[offset++] = (byte) (type & 0xFF); //1 octet, TYPE of AS_PATH_SEGMENT
Expand Down Expand Up @@ -119,7 +121,6 @@ public void setSegments(int[] segments)
{
this.segments = segments;
numberOfSegments = this.segments.length;
length = 2 + numberOfSegments * 2;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ public BGP_LS_MP_Reach_Attribute(byte [] bytes, int offset) {
super(bytes, offset);
int offset2=offset+this.mandatoryLength+5+this.getLengthofNextHopNetworkAddress();
lsNLRIList = new LinkedList<LinkStateNLRI>();

while(offset2 < length)
while(offset2 < length+offset)
{
LinkStateNLRI tempNLri;
int type = LinkStateNLRI.getType(bytes, offset2);
Expand Down Expand Up @@ -57,21 +56,21 @@ public void encode() {
//Encoding BGP_LS_MP_Reach_Attribute
// this.pathAttributeLength = 5+lsNLRI.getLength()+this.getLengthofNextHopNetworkAddress();
this.pathAttributeLength = 5+getLengthofNextHopNetworkAddress();
for(LinkStateNLRI ls : lsNLRIList)
for(int i=0; i< lsNLRIList.size() ;++i)
{
this.pathAttributeLength += ls.getTotalNLRILength();
lsNLRIList.get(i).encode();
this.pathAttributeLength += lsNLRIList.get(i).getTotalNLRILength();
}

this.setPathAttributeLength(pathAttributeLength);
this.bytes=new byte[this.getLength()];
encodeHeader();
encodeMP_Reach_Header();
int offset = this.getMandatoryLength()+5+this.getLengthofNextHopNetworkAddress();
for(LinkStateNLRI ls : lsNLRIList)
for(int i=0; i< lsNLRIList.size() ;++i)
{
ls.encode();
System.arraycopy(ls.getBytes(), 0, this.bytes, offset, ls.getTotalNLRILength());
offset += ls.getTotalNLRILength();
System.arraycopy(lsNLRIList.get(i).getBytes(), 0, this.bytes, offset, lsNLRIList.get(i).getTotalNLRILength());
offset += lsNLRIList.get(i).getTotalNLRILength();
}

}
Expand All @@ -83,6 +82,10 @@ public LinkStateNLRI getLsNLRI() {

public void setLsNLRI(LinkStateNLRI lsNLRI) {
this.lsNLRI = lsNLRI;
if (this.lsNLRIList.size()>0){
this.lsNLRIList=new LinkedList<LinkStateNLRI>();
}
this.lsNLRIList.add(lsNLRI);
}
public void setLsNLRIList(List<LinkStateNLRI> lsNLRIList){ this.lsNLRIList = lsNLRIList; }

Expand Down
3 changes: 3 additions & 0 deletions src/test/java/es/tid/tests/TestBGPAsPathAttribute.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public void testAsPathSegment()

as1.setSegments(segments);
as1.encode();

as2 = new AS_Path_Segment(as1.getBytes(), 0);

Assert.assertEquals("2-Both objects should be equal", as1, as2);
Expand All @@ -55,6 +56,8 @@ public void testAsPathAttribute()

AS_Path_Attribute ap2 = new AS_Path_Attribute(ap1.getBytes(), 0);
ap2.encode();
System.out.println("AP1 "+ap1.toString());
System.out.println("AP2 "+ap2.toString());

Assert.assertEquals("Both PathAttribute_AS_PATH should be equal", ap1, ap2);
Assert.assertArrayEquals("Bytes from both PathAttribute_AS_PATH objects should be the same", ap1.getBytes(), ap2.getBytes());
Expand Down

0 comments on commit 95e705d

Please sign in to comment.