FileDocCategorySizeDatePackage
NetworkAdminASNImpl.javaAPI DocAzureus 3.0.3.44233Wed Jul 11 22:48:30 BST 2007com.aelitis.azureus.core.networkmanager.admin.impl

NetworkAdminASNImpl

public class NetworkAdminASNImpl extends Object implements com.aelitis.azureus.core.networkmanager.admin.NetworkAdminASN

Fields Summary
private String
as
private String
asn
private String
bgp_prefix
Constructors Summary
protected NetworkAdminASNImpl(String _as, String _asn, String _bgp)

		as			= _as;
		asn			= _asn;
		bgp_prefix	= _bgp;
	
Methods Summary
public java.lang.StringgetAS()

		return( as==null?"":as );
	
public java.lang.StringgetASName()

		return( asn==null?"":asn );
	
public java.net.InetAddressgetBGPEndAddress()

		if ( bgp_prefix == null ){
			
			return( null );
		}
		
		try{
			return( getCIDREndAddress());
			
		}catch( NetworkAdminException e ){
			
			Debug.out(e);
			
			return( null );
		}
	
public java.lang.StringgetBGPPrefix()

		return( bgp_prefix==null?"":bgp_prefix );
	
public java.net.InetAddressgetBGPStartAddress()

		if ( bgp_prefix == null ){
			
			return( null );
		}
	
		try{
			return( getCIDRStartAddress());
			
		}catch( NetworkAdminException e ){
			
			Debug.out(e);
			
			return( null );
		}
	
protected java.net.InetAddressgetCIDREndAddress()


		int	pos = bgp_prefix.indexOf('/");
		
		try{
			InetAddress	start = InetAddress.getByName( bgp_prefix.substring(0,pos));
			
			int	cidr_mask = Integer.parseInt( bgp_prefix.substring( pos+1 ));
			
			int	rev_mask = 0;
			
			for (int i=0;i<32-cidr_mask;i++){
				
			
				rev_mask = ( rev_mask << 1 ) | 1;
			}
			
			byte[]	bytes = start.getAddress();
			
			bytes[0] |= (rev_mask>>24)&0xff;
			bytes[1] |= (rev_mask>>16)&0xff;
			bytes[2] |= (rev_mask>>8)&0xff;
			bytes[3] |= (rev_mask)&0xff;
			
			return( InetAddress.getByAddress( bytes ));
			
		}catch( Throwable e ){
			
			throw( new NetworkAdminException( "Parse failure for '" + bgp_prefix + "'", e ));
		}		
	
protected java.net.InetAddressgetCIDRStartAddress()

		int	pos = bgp_prefix.indexOf('/");
		
		try{
			return( InetAddress.getByName( bgp_prefix.substring(0,pos)));
			
		}catch( Throwable e ){
			
			throw( new NetworkAdminException( "Parse failure for '" + bgp_prefix + "'", e ));
		}
	
public java.lang.StringgetString()

		return( "as=" + getAS() + ",asn=" + getASName() + ", bgp_prefx=" + getBGPPrefix() + "[" +getBGPStartAddress() + "-" + getBGPEndAddress() + "]" );
	
public booleanmatchesCIDR(java.net.InetAddress address)

		if ( bgp_prefix == null || bgp_prefix.length() == 0 ){
			
			return( false );
		}
		
		try{
			InetAddress	start	= getCIDRStartAddress();
			InetAddress	end		= getCIDREndAddress();
			
			long	l_start = PRHelpers.addressToLong( start );
			long	l_end	= PRHelpers.addressToLong( end );
			
			long	test = PRHelpers.addressToLong( address );
			
			return( test >= l_start && test <= l_end );
			
		}catch( Throwable e ){
			
			Debug.printStackTrace(e);
			
			return( false );
		}
	
public booleansameAs(com.aelitis.azureus.core.networkmanager.admin.NetworkAdminASN other)

		return( getAS().equals( other.getAS()));
	
protected voidsetASName(java.lang.String s)

		asn		= s;