Freeside:4:Documentation:Developer/FS/addr block
From Freeside
Contents
NAME
FS::addr_block - Object methods for addr_block records
SYNOPSIS
use FS::addr_block; $record = new FS::addr_block \%hash; $record = new FS::addr_block { 'column' => 'value' }; $error = $record->insert; $error = $new_record->replace($old_record); $error = $record->delete; $error = $record->check;
DESCRIPTION
An FS::addr_block record describes an address block assigned for broadband access. FS::addr_block inherits from FS::Record. The following fields are currently supported:
- blocknum - primary key, used in FS::svc_broadband to associate services to the block.; routernum - the router (see FS::router) to which this block is assigned.; ip_gateway - the gateway address used by customers within this block.; ip_netmask - the netmask of the block, expressed as an integer.; manual_flag - prohibit automatic ip assignment from this block when true.; agentnum - optional agent number (see FS::agent)
METHODS
- new HASHREF
- Create a new record. To add the record to the database, see "insert".
- insert
- Adds this record to the database. If there is an error, returns the error, otherwise returns false.
- delete
- Deletes this record from the database. If there is an error, returns the error, otherwise returns false.
- replace OLD_RECORD
- Replaces OLD_RECORD with this one in the database. If there is an error, returns the error, otherwise returns false.
- At present it's not possible to reallocate a block to a different router except by deallocating it first, which requires that none of its addresses be assigned. This is probably as it should be.
- sub replace_check { my ( $new, $old ) = ( shift, shift );
unless($new->routernum == $old->routernum) { my @svc = $self->svc_broadband; if (@svc) { return 'Block has assigned addresses: '. join ', ', map {$_->ip_addr} @svc; } return 'Block is already allocated' if($new->routernum && $old->routernum); } '';
}
- check
- Checks all fields to make sure this is a valid record. If there is an error, returns the error, otherwise returns false. Called by the insert and replace methods.
- router
- Returns the FS::router object corresponding to this object. If the block is unassigned, returns undef.
- svc_broadband
- Returns a list of FS::svc_broadband objects associated with this object.
- NetAddr
- Returns a NetAddr::IP object for this block's address and netmask.
- cidr
- Returns a CIDR string for this block's address and netmask, i.e. 10.4.20.0/24
- next_free_addr
- Returns a NetAddr::IP object corresponding to the first unassigned address in the block (other than the network, broadcast, or gateway address). If there are no free addresses, returns nothing. There are never free addresses when manual_flag is true.
- There is no longer a method to return all free addresses in a block.
- allocate -- deprecated
- Allocates this address block to a router. Takes an FS::router object as an argument.
- At present it's not possible to reallocate a block to a different router except by deallocating it first, which requires that none of its addresses be assigned. This is probably as it should be.
- deallocate -- deprecated
- Deallocates the block (i.e. sets the routernum to 0). If any addresses in the block are assigned to services, it fails.
- split_block
- Splits this address block into two equal blocks, occupying the same space as the original block. The first of the two will also have the same blocknum. The gateway address of each block will be set to the first usable address, i.e. (network address)+1. Since this method is designed for use on unallocated blocks, this is probably the correct behavior.
- (At present, splitting allocated blocks is disallowed. Anyone who wants to implement this is reminded that each split costs three addresses, and any customers who were using these addresses will have to be moved; depending on how full the block was before being split, they might have to be moved to a different block. Anyone who still wants to implement it is asked to tie it to a configuration switch so that site admins can disallow it.)
- merge
- To be implemented.
- agent
- Returns the agent (see FS::agent) for this address block, if one exists.
- label
- Returns text including the router name, gateway ip, and netmask for this block.
- router
- Returns the router assigned to this block.
BUGS
Minimum block size should be a config option. It's hardcoded at /30 right now because that's the smallest block that makes any sense at all.