SSF.Net.Util
Class cidrBlock

java.lang.Object
  |
  +--SSF.Net.Util.cidrBlock

public class cidrBlock
extends java.lang.Object

Tree of CIDR blocks, constructed from a Net configuration using the optional "cidr" attributes provided for Net and link attributes. Each CIDR block in this tree represents one of three things: a Net, a link (ptp or LAN), or a placeholder block that doesn't correspond to any DML attribute, containing multiple link sub-blocks.

The block tree does the bookkeeping to maintain three distinct address maps. The NHI map addresses each network, host, and interface as N1:N2:N3:{...}Nn:H(I). The CIDR map addresses each network and link by its CIDR string, L1/L2/L3../Ln. The IP map addresses each network and link by the IP prefix associated with its CIDR block, and each interface of each host by an IP address offset from the prefix assigned to the link in which it appears as an attached interface.

To construct the three maps together, it suffices to construct a single CIDR block, passing the root network's dmlConfig and an IP prefix within which addresses are to be assigned. The code will make one pass over the DML to create the CIDR block tree and NHI map, another to compute the required address blocksizes for the IP map, and a third to assign IP prefixes and addresses.

The cidrBlock tree then serves as a translation table for all three maps, using utility functions {nhi,ip,cidr}_to_{nhi_ip_cidr}, each of which takes a String as an argument and returns another String.

If "cidr" attributes are partially or totally missing, the code will attempt to automatically supply numbers starting from CIDR_BASE. This is not foolproof, because of the amount of checking that would be involved (for example, the need for an additional pass to create a "reserved CIDR block map"). It's better to either uniformly supply CIDR addresses, or uniformly omit them.

BUGS


Field Summary
protected  cidrBlock ancestorBlock
          CIDR block where defined
protected  com.renesys.raceway.DML.Configuration blockConfig
          Cached configuration of the Net or link for which this is the address block descriptor.
static int CIDR_AUTOMATIC
           
static int CIDR_BASE
          CIDR number from which we number default sub-blocks: e.g., 0 or 1
static int CIDR_IN_USE
          Three-way flag for CIDR addressing.
static int CIDR_INDETERMINATE
           
 int cidr_number
          CIDR block number for this address block descriptor.
 java.lang.String cidr_prefix
          Global CIDR block address for this descriptor.
static java.lang.String CIDR_SEPARATOR
          Separator string for CIDR addresses
static int CIDR_status
           
static int CIDR_WIDTH
          Number of address bits that make up the entire address space
protected  java.util.Hashtable interfaces
          Table of interfaces for hosts that appear in this subnet.
static int IP_AUTOMATIC
           
static int IP_IN_USE
          Three-way flag for IP addressing.
static int IP_INDETERMINATE
           
 int ip_prefix
          IP address prefix assigned to this block.
 int ip_prefix_length
          Number of prefix bits in the local block of reserved addresses.
static int IP_status
           
protected  int nextCidr
          Next CIDR block number to be auto-assigned within this address block.
 int nhi_number
          NHI Network Address final component
 java.lang.String nhi_prefix
          NHI Network Address
static java.lang.String NHI_SEPARATOR
          Separator string for NHI addresses
protected  cidrBlock parentBlock
          CIDR block one level up from this one.
 int required
          Number of addresses required by this block, including the reserved net and broadcast addresses.
static boolean strict
          Set 'strict' to false to disable many CIDR/IP rules.
protected  java.util.Hashtable subblocks
          Table of CIDR sub-blocks.
protected  java.util.Hashtable subnets
          Table of sub-Nets.
 
Constructor Summary
cidrBlock(com.renesys.raceway.DML.Configuration cfg, java.lang.String use_IP)
          Constructor for a top-level CIDR block, given a DML configuration describing one outermost Net, which may not have an ID or a CIDR block number.
 
Method Summary
 java.util.Enumeration cidr_children()
          Return the CIDR blocks in the CIDR level underneath this one.
static java.lang.String cidr_concat(java.lang.String pre, int post)
          Concatenate the given CIDR addresses.
 cidrBlock cidr_parent()
          Return the CIDR block which is one CIDR level up from this one.
 java.lang.String configCIDR(com.renesys.raceway.DML.Configuration cfg, int offset)
           
 java.lang.String configIP(com.renesys.raceway.DML.Configuration cfg, int offset)
           
 boolean contains(int addr)
           
 boolean contains(int addr, int preflen)
           
 java.lang.String defined_in_net()
          Return the NHI address of the network in which this CIDR block (Net or Link) was defined.
 void dump_by_cidr()
           
 void dump_by_subnet()
           
 java.lang.Object getUDA(java.lang.String key)
          Retreive the value of a user-defined attribute from this CIDR block descriptor.
 java.lang.Object getUDA(java.lang.String key, java.lang.String kval, boolean flowdown, boolean override, java.lang.String concatString)
          Retreive the value of a user-defined attribute from this CIDR block descriptor.
 java.lang.String ip_to_nhi(int ipaddr, int ipprefix)
          IP address to NHI address.
 java.lang.String ip()
           
static void main(java.lang.String[] argv)
           
 java.lang.String net_nhi_to_ip(java.lang.String nhi_address)
          Returns the IP address of the Net whose NHI address is nhi_address.
 cidrBlock net_nhi(java.lang.String naddr)
          Returns the CIDR block corresponding to the specified Net's NHI address naddr.
 com.renesys.raceway.DML.Configuration networkConfiguration()
           
 java.util.Enumeration nhi_children()
          Return the CIDR blocks corresponding to subnets within this one.
static java.lang.String nhi_concat(java.lang.String pre, int post)
          Concatenate the given NHI addresses.
static java.lang.String nhi_concat(java.lang.String pre, java.lang.String post)
          Concatenate the given NHI addresses.
static java.lang.String nhi_host_interface(java.lang.String naddr)
          Return 'host(interface)' part of an NHI address: "N1:N2:N3:H(I)" --> "H(I)"
static java.lang.String nhi_host(java.lang.String naddr)
          Return 'host' part of an NHI address: "N1:N2:N3:H(I)" --> "H"
static java.lang.String nhi_interface(java.lang.String naddr)
          Return 'interface' part of an NHI address: "N1:N2:N3:H(I)" --> "I"
static java.lang.String nhi_net_host(java.lang.String naddr)
          Return 'network:host' part of an NHI address: "N1:N2:N3:H(I)" --> "N1:N2:N3:H"
static java.lang.String nhi_net(java.lang.String naddr)
          Return 'network' part of an NHI address: "N1:N2:N3:H(I)" --> "N1:N2:N3"
 cidrBlock nhi_parent()
          Return the CIDR block corresponding to the Net in which this block was defined: not necessarily the parent when multilevel CIDR strings are in use.
 java.lang.String nhi_to_cidr(java.lang.String nhi_address)
          NHI address to CIDR address
 java.lang.String nhi_to_ip(java.lang.String nhi_address)
          NHI host address to IP address.
 cidrBlock nhi(java.lang.String naddr)
          NHI address to CIDR block.
 int reserved()
          Utility function to compute number of addresses reserved in block
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CIDR_BASE

public static final int CIDR_BASE
CIDR number from which we number default sub-blocks: e.g., 0 or 1

See Also:
Constant Field Values

CIDR_WIDTH

public static final int CIDR_WIDTH
Number of address bits that make up the entire address space

See Also:
Constant Field Values

NHI_SEPARATOR

public static final java.lang.String NHI_SEPARATOR
Separator string for NHI addresses

See Also:
Constant Field Values

CIDR_SEPARATOR

public static final java.lang.String CIDR_SEPARATOR
Separator string for CIDR addresses

See Also:
Constant Field Values

cidr_number

public int cidr_number
CIDR block number for this address block descriptor.


cidr_prefix

public java.lang.String cidr_prefix
Global CIDR block address for this descriptor.


nhi_number

public int nhi_number
NHI Network Address final component


nhi_prefix

public java.lang.String nhi_prefix
NHI Network Address


ip_prefix

public int ip_prefix
IP address prefix assigned to this block.


ip_prefix_length

public int ip_prefix_length
Number of prefix bits in the local block of reserved addresses.


strict

public static boolean strict
Set 'strict' to false to disable many CIDR/IP rules. If 'strict' is true, you may not specify CIDR and IP in the same file, and you must be ruthlessly uniform in your application or omission of CIDR or IP attributes.


CIDR_IN_USE

public static final int CIDR_IN_USE
Three-way flag for CIDR addressing. CIDR_IN_USE signifies that the modeler wishes to specify explicit CIDR addresses, and their omission should be flagged as an error. CIDR_AUTOMATIC signifies that the modeler wishes to omit explicit CIDR addresses and let the framework choose them automatically, flagging "cidr" attributes as errors. CIDR_INDETERMINATE signifies that the decision has not yet been made. It is an error to manually specify both CIDR and IP in the same model.

See Also:
Constant Field Values

CIDR_AUTOMATIC

public static final int CIDR_AUTOMATIC
See Also:
Constant Field Values

CIDR_INDETERMINATE

public static final int CIDR_INDETERMINATE
See Also:
Constant Field Values

CIDR_status

public static int CIDR_status

IP_IN_USE

public static final int IP_IN_USE
Three-way flag for IP addressing. IP_IN_USE signifies that the modeler wishes to specify explicit IP addresses, and their omission should be flagged as an error. IP_AUTOMATIC signifies that the modeler wishes to omit explicit IP addresses and let the framework choose them automatically, flagging "ip" attributes as errors. IP_INDETERMINATE signifies that the decision has not yet been made. It is an error to manually specify both CIDR and IP in the same model.

See Also:
Constant Field Values

IP_AUTOMATIC

public static final int IP_AUTOMATIC
See Also:
Constant Field Values

IP_INDETERMINATE

public static final int IP_INDETERMINATE
See Also:
Constant Field Values

IP_status

public static int IP_status

blockConfig

protected com.renesys.raceway.DML.Configuration blockConfig
Cached configuration of the Net or link for which this is the address block descriptor. If blockConfig is null, this is a 'placeholder' cidrBlock created by a link or net with a multilevel cidr attribute; it does not correspond to any particular link or net.


subnets

protected java.util.Hashtable subnets
Table of sub-Nets. Key is Net.id (Integer); value is instance of cidrBlock corresponding to that sub-Net ID, if one exists.


interfaces

protected java.util.Hashtable interfaces
Table of interfaces for hosts that appear in this subnet. Key is relative NHI spec (String, "H(I)"), and value is a reference to the attachSpec describing the link.


ancestorBlock

protected cidrBlock ancestorBlock
CIDR block where defined


parentBlock

protected cidrBlock parentBlock
CIDR block one level up from this one.


subblocks

protected java.util.Hashtable subblocks
Table of CIDR sub-blocks. Key is Integer; value is an instance of cidrBlock corresponding to that CIDR ID at this level.


nextCidr

protected int nextCidr
Next CIDR block number to be auto-assigned within this address block.


required

public int required
Number of addresses required by this block, including the reserved net and broadcast addresses. May be smaller than reserved() because of blocksize rounding requirements.

Constructor Detail

cidrBlock

public cidrBlock(com.renesys.raceway.DML.Configuration cfg,
                 java.lang.String use_IP)
          throws com.renesys.raceway.DML.configException
Constructor for a top-level CIDR block, given a DML configuration describing one outermost Net, which may not have an ID or a CIDR block number. Its ID and CIDR block number are both zero.

Method Detail

ip

public java.lang.String ip()

ip_to_nhi

public java.lang.String ip_to_nhi(int ipaddr,
                                  int ipprefix)
IP address to NHI address.


nhi

public cidrBlock nhi(java.lang.String naddr)
NHI address to CIDR block. If the nhi address specifies an interface, return the CIDR block corresponding to the link in which that interface is attached; otherwise, return the CIDR block corresponding to the net containing the specified host. Note: nhi("1:2") is "host 2 in net 1", and NOT "net 2 in net 1" --- the final nhi address component is always interpreted as a host ID with an optional interface specification following in parentheses. Returns null if such nhi address does not exist in this cidrBlock.


net_nhi

public cidrBlock net_nhi(java.lang.String naddr)
Returns the CIDR block corresponding to the specified Net's NHI address naddr. Note: naddr = "1:2" means "net 2 in net 1" --- the final nhi address component is always interpreted as a Net id. Returns null if there is no such NHI address in this cidrBlock.


net_nhi_to_ip

public java.lang.String net_nhi_to_ip(java.lang.String nhi_address)
Returns the IP address of the Net whose NHI address is nhi_address. Note: nhi_address = "1:2" means "net 2 in net 1" --- the final nhi address component is always interpreted as a Net ID. Returns null if there is no such NHI address in this cidrBlock.


nhi_to_cidr

public java.lang.String nhi_to_cidr(java.lang.String nhi_address)
NHI address to CIDR address


nhi_to_ip

public java.lang.String nhi_to_ip(java.lang.String nhi_address)
NHI host address to IP address. Returns the interface IP address if host nhi_address has form like "1:2:3(0)"; returns the IP address of Net containing the host if nhi_address has form like "1:2:3". The last nhi address component is interpreted as a host ID.


defined_in_net

public java.lang.String defined_in_net()
Return the NHI address of the network in which this CIDR block (Net or Link) was defined.


nhi_concat

public static java.lang.String nhi_concat(java.lang.String pre,
                                          java.lang.String post)
Concatenate the given NHI addresses.


nhi_concat

public static java.lang.String nhi_concat(java.lang.String pre,
                                          int post)
Concatenate the given NHI addresses.


cidr_concat

public static java.lang.String cidr_concat(java.lang.String pre,
                                           int post)
Concatenate the given CIDR addresses.


nhi_net

public static java.lang.String nhi_net(java.lang.String naddr)
Return 'network' part of an NHI address: "N1:N2:N3:H(I)" --> "N1:N2:N3"


nhi_net_host

public static java.lang.String nhi_net_host(java.lang.String naddr)
Return 'network:host' part of an NHI address: "N1:N2:N3:H(I)" --> "N1:N2:N3:H"


nhi_host_interface

public static java.lang.String nhi_host_interface(java.lang.String naddr)
Return 'host(interface)' part of an NHI address: "N1:N2:N3:H(I)" --> "H(I)"


nhi_interface

public static java.lang.String nhi_interface(java.lang.String naddr)
Return 'interface' part of an NHI address: "N1:N2:N3:H(I)" --> "I"


nhi_host

public static java.lang.String nhi_host(java.lang.String naddr)
Return 'host' part of an NHI address: "N1:N2:N3:H(I)" --> "H"


cidr_parent

public cidrBlock cidr_parent()
Return the CIDR block which is one CIDR level up from this one.


nhi_parent

public cidrBlock nhi_parent()
Return the CIDR block corresponding to the Net in which this block was defined: not necessarily the parent when multilevel CIDR strings are in use.


cidr_children

public java.util.Enumeration cidr_children()
Return the CIDR blocks in the CIDR level underneath this one.


nhi_children

public java.util.Enumeration nhi_children()
Return the CIDR blocks corresponding to subnets within this one.


networkConfiguration

public com.renesys.raceway.DML.Configuration networkConfiguration()

reserved

public final int reserved()
Utility function to compute number of addresses reserved in block


contains

public boolean contains(int addr,
                        int preflen)

contains

public boolean contains(int addr)

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

dump_by_subnet

public void dump_by_subnet()

dump_by_cidr

public void dump_by_cidr()

configIP

public java.lang.String configIP(com.renesys.raceway.DML.Configuration cfg,
                                 int offset)
                          throws com.renesys.raceway.DML.configException
com.renesys.raceway.DML.configException

configCIDR

public java.lang.String configCIDR(com.renesys.raceway.DML.Configuration cfg,
                                   int offset)
                            throws com.renesys.raceway.DML.configException
com.renesys.raceway.DML.configException

getUDA

public java.lang.Object getUDA(java.lang.String key)
                        throws com.renesys.raceway.DML.configException
Retreive the value of a user-defined attribute from this CIDR block descriptor. If the attribute is omitted, attempt to use the default value specified in the containing network; otherwise, the local value overrides the default. Return single attribute values, not a concatenation of parent and child values leading back to the root.

com.renesys.raceway.DML.configException

getUDA

public java.lang.Object getUDA(java.lang.String key,
                               java.lang.String kval,
                               boolean flowdown,
                               boolean override,
                               java.lang.String concatString)
                        throws com.renesys.raceway.DML.configException
Retreive the value of a user-defined attribute from this CIDR block descriptor.

com.renesys.raceway.DML.configException

main

public static void main(java.lang.String[] argv)