Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
9401224
SCRUM-2487 - mavenize
dragank Feb 26, 2015
1e18aac
SCRUM-2487 - mavenize
dragank Feb 26, 2015
363b594
SCRUM-2487 - mavenize
dragank Feb 26, 2015
dabbfe0
Fix double-offset increment bug in ExtCommunities, and use ASPLAIN no…
codebje Mar 3, 2015
518b418
SCRUM-2487 - Allow writes to file rather than stdout
dragank Mar 3, 2015
05e26c6
SCRUM-2487 - Short circuit System.exit()
dragank Mar 3, 2015
3398bb1
SCRUM-2487 - Add option to capture output errors to a StringBuilder
dragank Mar 3, 2015
03aec8e
Fixed issue with BGPFileReader reading from slow input streams.
rlcintra Mar 19, 2015
c1a8276
Fixed indentation from previous commit (tabs? really?!).
rlcintra Mar 19, 2015
94ba8d8
Added code to ignore the deprecated attribute type 20 (Connector Attr…
rlcintra Apr 16, 2015
7dd7f1b
Added partial support to attribute type 128 (ATTR_SET).
rlcintra Oct 9, 2015
0ec954e
[master] .gitignore
tomhrr Jan 3, 2017
38adab6
[feature/SCRUM-3461] ignore large_community
tomhrr Jan 3, 2017
13c9231
[feature/SCRUM-3461] check for expected content
tomhrr Jan 4, 2017
1356349
Merge pull request #1 from APNIC-net/feature/SCRUM-3461
tomhrr Jan 4, 2017
064715f
[master] bump version
tomhrr Jan 4, 2017
cb5f68d
[master] move to snapshot version
tomhrr Jan 4, 2017
83b8d93
Do not use "record" in exceptions, as it could be huge in malformed MRT.
omuravskiy May 17, 2017
51ce709
[RIPE-NCC-master] fix conflicts
tomhrr May 17, 2017
4a812ea
Merge branch 'RIPE-NCC-master'
tomhrr May 17, 2017
eaa73d3
Keep binary data and add methods to retrieve it after parsing
omuravskiy Jul 3, 2017
8b1ed20
Adding getter for body in MRTRecord
edominguezro Jul 3, 2017
1e25390
Adding getter for header in MRTRecord
edominguezro Jul 3, 2017
a49836b
Reverse default AFI (IPv4 by default)
omuravskiy Jul 11, 2017
9845b98
Keep unsupported Bgp4Update Attributes
omuravskiy Jul 11, 2017
fb6e6ef
Merge branch 'ripencc-keep-binary' of https://github.com/RIPE-NCC/jav…
omuravskiy Jul 11, 2017
02a23b6
Adding srcIP and srcAS attributes to Open and Notification objects.
edominguezro Jul 17, 2017
49990c2
Parsing mrt records based on rfc1771.
edominguezro Aug 1, 2017
302285e
When announcements and withdraws are defined in this bgp message posi…
edominguezro Feb 16, 2018
eec9892
GIIDEV-209 Fixing 4-byte ASNs in the path are treated as signed integer
edominguezro Feb 16, 2018
729aab1
Doing a "hack" in order to show Ipv6 format in Ipv4 embedded prefixes…
edominguezro Feb 19, 2018
a8e85d5
Cleaning up unused import
edominguezro Feb 19, 2018
5245ba5
Changing testing
edominguezro Feb 19, 2018
c810808
Copy arrays using System.arraycopy()
omuravskiy Feb 20, 2018
914aa47
Merge remote-tracking branch 'origin/ripencc-keep-binary'
omuravskiy Feb 20, 2018
b42e301
Merge pull request #3 from RIPE-NCC/master
tomhrr Feb 20, 2018
75451d0
[master] add .travis.yml
tomhrr Feb 20, 2018
2d978ec
Adding getter for the embedded ipv4-ipv6
edominguezro Feb 21, 2018
4debb6f
Fast fix for wrong ipv6 parse
edominguezro Feb 21, 2018
099d38e
Fix more 32-bit ASN / unsigned lengths issues.
omuravskiy Feb 21, 2018
4f307ba
Loosen requirements for collection type in constructor.
omuravskiy Feb 21, 2018
59780b7
Add tests for AS and ASPath
omuravskiy Feb 22, 2018
85c9cb2
Convert JUnit test to TestNG
omuravskiy Feb 22, 2018
95277a7
Updating the Mrtconstants.ipAddressString method in order to allow th…
edominguezro Mar 1, 2018
3125c7d
Merge remote-tracking branch 'origin/master'
edominguezro Mar 1, 2018
45c6b27
Fix AS_CONFED_SEQUENCE and AS_CONFED_SET constants
omuravskiy Mar 23, 2018
88537ea
Merge pull request #4 from RIPE-NCC/track-apnic
tomhrr Mar 25, 2018
a47fa2c
Multiple fixes and improvements:
omuravskiy Aug 8, 2018
98f6db9
Process advertisements even if there were withdrawals :)
omuravskiy Sep 3, 2018
4ae7fb1
Recognise and parse End-Of-Rib marker
omuravskiy Sep 3, 2018
b8cbe70
Added ASPath functionality
andrekampert Sep 6, 2018
9e3a6f2
Improved toString handling
andrekampert Sep 6, 2018
94e9d93
Implement getAsList for all AS instances
andrekampert Sep 6, 2018
85ab9d2
Do not overwrite ASPath if attribute of type 0 received.
omuravskiy Sep 26, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .gitignore
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,14 @@ local.properties
# Eclipse project files
.classpath
.project

*.iml
*.ipr
*.iws
.idea
target
atlassian-ide-plugin.xml
.settings
.DS_Store

*.swp
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
language: java
3 changes: 0 additions & 3 deletions README.md
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,4 @@ java-mrt

Java library to parse the binary MRT format.

I have used this library over the last years extensively.
Please send any bug fixes to me paaguti :#at#: gmail _dot_ com

This library is released under LGPL license. Read LICENSE.txt.
8 changes: 4 additions & 4 deletions build.xml
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project name = "Paquete análisis BGP-4" default = "rebuild">
<property name = "outputdir" value = "."/>
<property name = "classdir" value = "./bin" />
<property name = "sourcedir" value = "./src" />
<property name = "outputdir" value = "./target"/>
<property name = "classdir" value = "./target/classes" />
<property name = "sourcedir" value = "./src/main/java" />
<property name = "debug" value = "false" />
<property name = "mrt.main.class" value = "org.java-mrt.progs.route_btoa" />
<property name = "mrt.main.class" value = "org.javamrt.progs.route_btoa" />

<target name = "cleansrc" description = "Borra los backups">
<tstamp/>
Expand Down
66 changes: 66 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>net.apnic.mrt</groupId>
<artifactId>mrt</artifactId>
<version>0.0.3-SNAPSHOT</version>
<packaging>jar</packaging>

<name>Java MRT File Dumper</name>
<description>Java Multi-Threaded Routing Toolkit File Dumper</description>
<url>https://github.com/APNIC-net/java-mrt</url>

<scm>
<url>>https://github.com/APNIC-net/java-mrt</url>
<connection>scm:git:git@github.com:APNIC-net/java-mrt.git</connection>
<developerConnection>scm:git:git@github.com:APNIC-net/java-mrt.git</developerConnection>
</scm>

<distributionManagement>
<repository>
<id>nexus-staging</id>
<name>Nexus Staging Repository</name>
<url>http://nexus.apnic.net:8081/nexus/content/repositories/staging</url>
</repository>
<snapshotRepository>
<id>nexus-snapshots</id>
<name>Nexus Snapshot Repository</name>
<url>http://nexus.apnic.net:8081/nexus/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>org.javamrt.progs.route_btoa</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>
101 changes: 38 additions & 63 deletions src/org/javamrt/mrt/AS.java → src/main/java/org/javamrt/mrt/AS.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@

package org.javamrt.mrt;

import java.math.BigInteger;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
* @author paag
Expand All @@ -16,81 +19,44 @@
public class AS implements Comparable<AS>, Comparator<AS> {
public static final int AS_TRANS = 23456;
public static final AS NullAS = new AS(0);
// protected long ASnumber;
protected byte ASCode[] = {0,0,0,0};
private long asNumber;

protected AS() {
}

public AS(long ASnumber) {
setASCode(ASnumber & 0xffffffff);
asNumber = ASnumber & 0xffffffffL;
}

public AS(byte[] as) throws Exception {
setASCode(as);
}


private void setASCode(long val) {
for (int i = 0; i < 4; i++)
ASCode[i] = (byte) ((val >> ((3 - i) * 8)) & 0xff);
}

private void setASCode(byte[] newval) throws Exception {
if (newval.length == 2) {
this.ASCode[0] =
this.ASCode[1] = 0;
this.ASCode[2] = newval[0];
this.ASCode[3] = newval[1];
} else if (newval.length == 4) {
this.ASCode[0] = newval[0];
this.ASCode[1] = newval[1];
this.ASCode[2] = newval[2];
this.ASCode[3] = newval[3];
} else
throw new Exception(String.format("AS must be 2 or 4 bytes long (%d not allowed)",newval.length));
public AS(byte[] as) {
if (as.length != 2 && as.length != 4) {
throw new IllegalArgumentException(String.format("AS must be 2 or 4 bytes long (%d not allowed)", as.length));
}
asNumber = new BigInteger(1, as).longValue();
}

public long getASN() {
long result = 0;
for (int i=0; i<ASCode.length;i++) {
result = (result << 8) & 0xffffff00;
result = result | (ASCode[i] & 0x000000ff);
}
return result;
return asNumber;
}

public void setASN(long ASnumber) {
this.setASCode(ASnumber & 0xffffffff);
this.asNumber = ASnumber & 0xffffffffL;
}

// public long getASN() {
// return this.ASnumber;
// }


public int compareTo(org.javamrt.mrt.AS other) {
return compare(this, other);
}

public int compare(org.javamrt.mrt.AS as1, org.javamrt.mrt.AS as2) {
for (int i=0;i<4;i++) {
if (as1.ASCode[i] == as2.ASCode[i])
continue;
return ((int)as1.ASCode[i] & 0xff) - ((int)as2.ASCode[i] & 0xff);
}
return 0;
return Long.compare(as1.asNumber, as2.asNumber);
}

/**
* @param AS other
* @return true if the other AS
*/
private boolean equals(AS other) {
for (int i=0; i<4; i++)
if (this.ASCode[i] != other.ASCode[i])
return false;
return true;
return other != null && this.asNumber == other.asNumber;
}

/**
Expand Down Expand Up @@ -118,38 +84,36 @@ public boolean equals(Object other) {
return false;
}

@Override
public int hashCode() {
return Long.hashCode(asNumber);
}

/**
* @return true if this is a 4 byte AS number
*/
public boolean is4Byte() {
return this.ASCode[0] != 0 || this.ASCode[1] != 0;
return asNumber > 0xFFFFL;
}

/**
* @return true if the AS number is 23456, the 4 byte AS place holder
* comparison is byte by byte
* @return true if the AS number is 23456
*/
public boolean isPlaceholder() {
return this.equals(AS_TRANS);
return asNumber == AS_TRANS;
}

/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
public String toString() {
if (this.equals(0)) return "AS_NULL";
if (this.equals(AS_TRANS)) return "AS_TRANS";
if (this.is4Byte()) return String.format("%d.%d",hiWord(),loWord());
return String.format("%d", loWord());
}
// this has never worked, so do not think we should fix it now
// if (this.equals(0)) return "AS_NULL";
// if (this.equals(AS_TRANS)) return "AS_TRANS";

private int hiWord() {
return ((this.ASCode[0] & 0xff) << 8) | (this.ASCode[1] & 0xff);
return String.valueOf(asNumber);
}

private int loWord() {
return ((this.ASCode[2] & 0xff) << 8) | (this.ASCode[3] & 0xff);
}
/**
* @param prefix
* @return a String containing the prefix followed by the AS textual representation
Expand All @@ -173,11 +137,22 @@ public static AS parseString(String asspec) throws Exception {
asnum = asnum * 0x10000L + asnum1;
result = new AS(asnum);
} else {
result = new AS(Long.parseLong(asspec));
long number = Long.parseLong(asspec);
if (number < 0 || number > 0xFFFFFFFFL) {
throw new IllegalArgumentException("number must be in [0,4294967295]");
}
result = new AS(number);
}
} else {
throw new Exception ("Incorrect AS specification: "+asspec);
}
return result;
}

/**
* @return list of ASNs, especially useful when not interested in whether it is some type of set, but just want to deal with the numbers
*/
public List<AS> getASList() {
return Collections.singletonList(this);
}
}
30 changes: 30 additions & 0 deletions src/main/java/org/javamrt/mrt/ASConfedSequence.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// This file is part of java-mrt
// A library to parse MRT files

// This file is released under LGPL 3.0
// http://www.gnu.org/licenses/lgpl-3.0-standalone.html

package org.javamrt.mrt;

import java.util.List;
import java.util.LinkedList;
import java.util.stream.Collectors;

public class ASConfedSequence extends AS {
LinkedList<AS> asList;

public ASConfedSequence(List<AS> asList) {
this.asList = new LinkedList<>();
this.asList.addAll(asList);
}

@Override
public String toString() {
return asList.stream().map(AS::toString).collect(Collectors.joining(" ", "[", "]"));
}

@Override
public List<AS> getASList() {
return this.asList;
}
}
32 changes: 32 additions & 0 deletions src/main/java/org/javamrt/mrt/ASConfedSet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// This file is part of java-mrt
// A library to parse MRT files

// This file is released under LGPL 3.0
// http://www.gnu.org/licenses/lgpl-3.0-standalone.html

package org.javamrt.mrt;

import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;

public class ASConfedSet extends AS {

private LinkedList<AS> asList;

public ASConfedSet(final List<AS> asList) {
this.asList = new LinkedList<>();
this.asList.addAll(asList);
}

@Override
public String toString() {
return asList.stream().map(AS::toString).collect(Collectors.joining(" ", "{", "}"));
}

@Override
public List<AS> getASList() {
return this.asList;
}
}

Loading