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.
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
To get a local copy up and running follow these simple steps.
Install the following libraries
pip
pip install pip --upgrade --user
Clone the repo
git clone https://github.com/finsysadmin/Cisco-CUBE.git
Edit Database credentials accordingly to connect to your DB on function dbconnect
Install dependencies
pip install -r requirements.txt
Run the program main
Configure your database to connect correctly by replacing data on def dbconnect
appropriately
Enter the configurations of your cisco device by providing hostname,port,username and password to connect.
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 |
Application will read the database, check that the dial peer preferences and set them for each destination using the def write_config(self)
function.
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
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
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")
See the open issues for a list of proposed features (and known issues).
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.
git checkout -b feature/AmazingFeature
)git commit -m 'Add some AmazingFeature'
)git push origin feature/AmazingFeature
)Distributed under the MIT License. for more information.
Project Link: https://github.com/finsysadmin/Cisco-CUBE
Code Exchange Community
Get help, share code, and collaborate with other developers in the Code Exchange community.View Community