Installation Instructions
*************************

1. Build executable
At first you need to configure and build main bgphist executable.
To configure build environment please run `./configure' command.
Probably you should specify library and include paths for mysql and pcre libraries:
`LDFLAGS="-L/usr/local/lib -L/usr/local/lib/mysql" CFLAGS="-I/usr/local/include" ./configure --with-mysql'
After success configuration simply run make.
make will build bgphist executable.

2. Create backend database
To store BGP data into relational database, you should created data tables and stored procedures.
2.1. MySQL database
2.1.1. Create database
It not required but strongly recommend that you use separate database for bgphist.
For example we'll name this database as `bgplog'.
You can create such database on your MySQL sever with command:
`mysqladmin create bgplog'

You may need to specify DBA username and password like this: `mysqladmin -u root -p rootspassword create bgplog'. 

2.1.2. Create database tables and procedures.
After creating database you should create tables to store data and procedures.
`mysql -uroot [-prootspassword] bgplog < contrib/mysql/create_db.sql'

2.1.3. Create database user to access data.
After that you should create a separate user account which will access data and execute procedures.
For example - username will be `bgplogger' with password `bgppwd123' from localhost.
`mysql -uroot [-prootspassword] 
grant all privileges on bgplog.* to 'bgplogger'@'localhost' identified by 'bgppwd123';
'

2.2. Oracle database
2.2.1. You can use existing database schema, but it's recommended to create separate tablespace and schema/user.
Example commands to do it:
create tablespace bgpview datafile '/opt/app/oracle/oradata/orcl/bgpview01.dbf' size 100m autoextend on online;
create user bgplogger identified by "bgppwd123" default tablespace bgpview quota unlimited on bgpview;
grant all privileges to bgplogger;
2.2.2. Create database objects.
Log in as selected user (bgplogger for example) and run contrib/oracle/create_db.sql
 

3. Configure router.
bgphist process will connect to your router bgp process and listen all updates, so you should configure a new internal bgp neighbor
 on your BGP router (route reflector is recommended) with all interesting address families.
Optionally you can specify passive mode for your bgphist server.

4. Run bgphist to collect routing data
If you simply run `../bgphist' it will say a little help:
./bgphist: -p <bgp peer ip> -a <ASN> -d <database type>[:<database connection params>] -w <async wait msec> -f play capture file instead of bgp router connect
 Databases:
  text
  oci:<user>/<password>@<tnsname>
  mysql:<mysql host>:<mysqldb>:<user>:<pwd>

-p - IP address of your BGP router
-a - Your Autonomous System number
-d - Backend parameters 
-w - wait cycle for async DB update mode. 10000 recommended.
-f - extract BGP session data from binary file instead of router.

When you run bgphist with all arguments it will attempt to connect to specified router.
if connection will be unsuccesfull or in error case, bgphist simply quit.
If you need automatic reconnection (like router) you should made a simple shell script like this:
cat > bgphist.sh
#!/bin/bash
while true; do
./bgphist -p 1.1.1.1 -w 10000 -a 100 -d mysql:127.0.0.1:bgplog:bgplogger:bgppwd123
sleep 60
done
<Ctrl+D>
chmod a+x bgphist.sh
nohup ./bgphist.sh 1>/dev/null 2>/dev/null &

5. Configure rotation script
If you want bgphist for work in 24x7x365 mode with MySQL backend you should configure database table rotation script.
You will need perl with DBI and DBD::mysql modules.
Example is contrib/mysql/rotate_logs.pl
You should specify database credentials in this script and install it in the crontab, so this script will execute every month.
This script will rotate log tables and include it in myisam_mrg virtual tables.

6. Setup PHP frontend
To use PHP frontend you should install Apache web server with PHP and PHP should have mysql database driver.
To proper handle 64-bit integers, you should use 64-bit plaform with PHP, or PHP should be compiled with libgmp.

