Logo

Cisco CUBE Project

About The Project

Product Name Screen Shot

Description

A Python script to automate assignment of preference to voice dial peers based on the calling rate of a specific destination for each SIP Trunk provider in an enterprise and therefore achieving least cost routing.

Built With

  • Python 3.9

Software versions Used

  • Cisco CSR 1000V - csr1000v-universalk9.16.12
  • Cisco Unified Border Element Version 14
  • Microsoft SQL Server Express 2019

Python Libraries

  • Paramiko
  • http.client

Database

The following Tables exists.

Tables Contains
areacode Service Provider code (SPCode), Destination area code (AREA), Charges per minute for the respective destination code (UNIT_CHG).
gateway Service provider code (SCODE). An organization can have more than one service provider and each service provider can have more
pref_sip_operators Preference (PREF), Area Code (AREA), Service provider code (SPCODE) and Gateway(GW).

Stored procedure

util_get_sip_rank
This is routine is called by the script and pass the phone number calling to return the dial peer preferences

Getting Started

To get a local copy up and running follow these simple steps.

Prerequisites

Program setup

Install the following libraries
pip

pip install pip --upgrade --user

Installation

  1. Clone the repo

    git clone https://github.com/finsysadmin/Cisco-CUBE.git
  2. Edit Database credentials accordingly to connect to your DB on function dbconnect

  3. Install dependencies

    pip install -r requirements.txt
  4. Run the program main

Configuration before running script

  1. Configure your database to connect correctly by replacing data on def dbconnect appropriately

  2. Enter the configurations of your cisco device by providing hostname,port,username and password to connect.

Database Operations

By callling Database stored procedure util_get_sip_rank and passing the dialing Number as parameter, the procedure returns the charges for the respective
country code and arrange them in ascending order.

For example the result shown below :

PREF (Preference) AREA (Area Code ) UNIT_CHG QOS_RATE SPCODE (Service provider code ) GW (Gateway) SIPSTATUS
1 254 0.060000 NULL 02 0 NULL
2 254 0.060000 NULL 02 1 NULL
3 254 0.060000 NULL 02 2 NULL
4 254 0.091700 NULL 06 0 NULL
5 254 0.091700 NULL 05 0 NULL

Call flow

Application will read the database, check that the dial peer preferences and set them for each destination using the def write_config(self) function.

For example for international calls to Kenya with country code +254:

dial-peer voice 12541 voip
preference 1
destination-pattern 00254T
session protocol sipv2
session target ipv4:1.1.1.1

!dial-peer voice 12542 voip
preference 2
destination-pattern [08]00T
session protocol sipv2
session target ipv4:2.2.2.2

Outgoing calls will be sent through the provider specified in the dial peer with the lowest preference for that destination

Code Samples

DB connect function

def dbconnect(self, server=None):
        server = "Ip address"
        database = "DBname"
        tcon = "yes"
        uname = "username"
        pword = "pass"

        conn = pyodbc.connect(driver='{SQL Server Native Client 11.0}', host=server, database=database,
                              user=uname, password=pword)
        self.connection = conn

Write config to cisco device

 def write_config(self):
        preference = 0
        for dial_peer in self.preferences:
            # Create dial peer
            peer = str(1) + str(dial_peer.AREA) + str(dial_peer.SPCODE) + str(dial_peer.GW)
            # write dial peer and preference
            self.connection.send("dial-peer voice " + peer + " voip\n")  # dial-peer voice 1 254 3 voip
            self.connection.send("preference " + str(preference) + "\n")  # preference 0
            preference = preference + 1
            time.sleep(1)

        router_output = self.connection.recv(65535)
        # Test for reading command output
        print(str(router_output) + "\n")

Credits

  1. Cyrus Muchiri
  2. Mwaura Gitonga
  3. Stanley Mandela

Roadmap

See the open issues for a list of proposed features (and known issues).

Contributing

Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Distributed under the MIT License. for more information.

Contact

Project Link: https://github.com/finsysadmin/Cisco-CUBE

Acknowledgements

View code on GitHub

Code Exchange Community

Get help, share code, and collaborate with other developers in the Code Exchange community.View Community
Disclaimer:
Cisco provides Code Exchange for convenience and informational purposes only, with no support of any kind. This page contains information and links from third-party websites that are governed by their own separate terms. Reference to a project or contributor on this page does not imply any affiliation with or endorsement by Cisco.