Location: PHPKode > scripts > ONU > onu/olt.php
<?php
/*
* author: hide@address.com
*
* OLT , onu Class 
*
*
*	Copyright (C) 2008 Fernando André
*	
*	This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; *	either version 2 of the License, or (at your option) any later version.
*
*	This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR *	PURPOSE. See the GNU General Public License for more details.
*
*	You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite *	330, Boston, MA 02111-1307 USA
*
**/

class olt {

	public $community;

	/*
	* @params $ip ipv4 address of the OLT to connect
	* create the object and specify the ip address to use
	*/
	function olt($ip){
		$this->ip = $ip;
	}
	/*
	* return the snmp community used to connect to the $OLT
	* @params string IP address of the olt
	* @return string community
	*/
	function GetCommunity($oltIP){
		return $this->community;
	}
	/*
	* set's the community to be used for the OLT
	* @params string community
	*/
	function setCommunity($community) {
		$this->community = $community;
	}

	/*
	* Get the index number by using a mac address has description
	* @params $onuMAC mac address before must be removed the first left zeros leaving only one in the format 0:0:7b:xx:xx
	* @return integer	Index of the oid
	*/
	function GetOnuIndexByDescr($onuMac){
		$onuMac = $this->convertmac($onuMac);

		$ifPhy = "1.3.6.1.2.1.2.2.1.6";
		$result = $this->snmpwalker($ifPhy);
		
		if ( empty($result) ) return false;

		foreach ( $result as $vv => $var ) {
			$res = strstr($var, $onuMac);
			if ( $res !== false ) {
				$r = explode(".", $vv );
				return $r[count($r)-1];
			}
		}
	}
	/*
	* Get list of index's in the OLT (good for testing)
	*/
	function GetOltIndex(){
		$ifIndex = "1.3.6.1.2.1.2.2.1.1";
		$result = $this->snmpwalker($object);

		if ( empty($result)) return false;

		for ($i=0; $i < count($result); $i++ ){
			print $result[$i]."\n";
		}
	}
	/*
	* Get ONU index by PON PORT 
	* @params string OLT port description ex(Pon-onu2/1/62)
	*/
	function GetOnuIndexByePon($port) {
		$oidDescr = "1.3.6.1.2.1.2.2.1.2";
		$result = $this->snmpwalker($oidDescr);
		
		if ( empty($result) ) return false;

		foreach ( $result as $vv => $var ) {
			$res = strstr($var, $port);
			if ( $res !== false ) {
				$r = explode(".", $vv );
				return $r[count($r)-1];
			}
		}

		return false;

	}
	/*
	* used to do basic query's
	*/
	function snmpquery($object) {
		return $string = snmpget($this->ip, $this->community, $object);
	}
	/*
	* real walker
	*/
	function snmpwalker($object) {
		return snmprealwalk($this->ip, $this->community, $object);
	}
	/*
	* If you know the index get the onu by it's index
	* @param $index integer
	* @return object $onu
	*/
	function getOnubyIndex($index) {
		$this->community;
		$onu = new onu();
		$onu->setOlt($this);
		$onu->setIndex($index);
		$onu->load();

		return $onu;
	}
	/*
	* Convert the mac address to something that can be found on the OLT
	* @params $mac address
	* @return string mac address
	*/
	function convertmac($mac){
		$mac = strtolower(str_replace(".","", $mac));
	
		$mac = delimitermac($mac);

		$striped = explode(":", $mac);
		$c = count($striped);
		for ( $i=0; $i < $c ; $i++ )
		{
			if( $striped[$i][0] == '0' ){
				$striped[$i][0] = ' ';
			}
		}
	
		// Implode the dashes into the string mac
		$mac = implode(":", $striped);
		$mac = str_replace(" ","",$mac);
		$this->mac = $mac;
		return $mac;
	}

}


// 


?>
Return current item: ONU