Skip to content

Python library and sample apps and tools to work with Brocade SDN Controller RESTCONF interface. Scroll down for more info.

License

BSD-3-Clause, BSD-3-Clause licenses found

Licenses found

BSD-3-Clause
LICENSE
BSD-3-Clause
LICENSE.md

pruiksmalw/pybvc

 
 

pybvc Build Status

Python library and samples to program your network via the Brocade SDN Controller (OpenDaylight)

Other Brocade SDN Controller Libraries

Current Version:

1.3.3

Prerequisites

  • Python 2.7.x:
    • Test if your system already has it

      python --version
      • If it is installed you should see a response like this (the last digit may be different):
      Python 2.7.5
      
  • pip:
    • Test if your system already has it:

      pip --version
      • If it is installed you should see a response similar to this (as long as it is not an error response):
      pip 6.0.8 from /Library/Python/2.7/site-packages/pip-6.0.8-py2.7.egg (python 2.7)

Installation:

sudo pip install pybvc

Upgrade:

sudo pip install pybvc --upgrade

Check installed version:

pip show pybvc

Sample Applications:

There are many sample applications demonstrating the use of the pybvc library with controller and netconf devices. You do need to install pybvc for the samples to work.

  • To install samples:

    git clone https://github.com/brcdcomm/pybvcsamples.git
  • List of samples: - Sample Applications

Documentation:

Contribute:

If you want to contribute to this project, fantastic! Any contribution is welcome: bug fix, new samples, additions to pybvc library, documentation, etc. Please check out our CONTRIBUTE.md file for how to do this:

Twitter:

If you use twitter, then follow @jebpublic. This is where announcements about updates are sent.

Example 1: Add and remove firewall on Vyatta vrouter5600 via Brocade SDN Controller:

import pybvc

from pybvc.netconfdev.vrouter.vrouter5600 import VRouter5600, Firewall, Rules, Rule
from pybvc.common.status import STATUS
from pybvc.controller.controller import Controller

print (">>> Create Brocade SDN  controller instance")
ctrl = Controller("172.22.18.186", "8181" , "admin" , "admin") 

print (">>> Create Vyatta Router 5600 instance")
vrouter = VRouter5600(ctrl, "vRouter", "172.22.17.107", 830, "vyatta", "vyatta")


print (">>> Connect Vyatta Router 5600 to Brocade SDN Controller via NETCONF")
result = ctrl.add_netconf_node(vrouter)

print (">>> Define new firewall instance ACCEPT-SRC-IPADDR") 
firewall1 = Firewall()    
rules = Rules("ACCEPT-SRC-IPADDR")    
rule = Rule(30)
rule.add_action("accept")
rule.add_source_address("172.22.17.108")    
rules.add_rule(rule)
firewall1.add_rules(rules)


print (">>> Create ACCEPT-SRC-IPADDR on vrouter 5600") 
result = vrouter.create_firewall_instance(firewall1)


print (">>> Define new firewall instance DROP-ICMP") 
firewall2 = Firewall()    
rules = Rules("DROP-ICMP")    
rule = Rule(40)
rule.add_action("drop")
rule.add_icmp_typename("ping")
rules.add_rule(rule)
firewall2.add_rules(rules)   

print (">>> Create DROP-ICMP on vrouter 5600")  
result = vrouter.create_firewall_instance(firewall2)

print ("<<< Apply ACCEPT-SRC-IPADDR to inbound traffic and DROP-ICMP to outbound traffic on the dp0p1p7 dataplane interface" ) 
result = vrouter.set_dataplane_interface_firewall("dp0p1p7", "ACCEPT-SRC-IPADDR", "DROP-ICMP")

print (">>> Remove firewalls from dp0p1p7 dataplane interface")  
result = vrouter.delete_dataplane_interface_firewall("dp0p1p7")

print (">>> Remove firewall definitions from vrouter 5600")
result = vrouter.delete_firewall_instance(firewall1)
result = vrouter.delete_firewall_instance(firewall2)

Example 2: Add a flow that drops packets that match in-port, Ethernet src/dest addr, ip src/dest/dscp/ecn/protocol and tcp src/dest ports

import time
import json
import pybvc


from pybvc.controller.controller import Controller
from pybvc.openflowdev.ofswitch import OFSwitch
from pybvc.openflowdev.ofswitch import FlowEntry
from pybvc.openflowdev.ofswitch import Instruction
from pybvc.openflowdev.ofswitch import DropAction
from pybvc.openflowdev.ofswitch import Match

from pybvc.common.status import STATUS
from pybvc.common.utils import load_dict_from_file

ctrl = Controller("192.168.56.101", "8181", "admin", "admin")
node = "openflow:1" # (name:DPID)
ofswitch = OFSwitch(ctrl, node)

# --- Flow
flow_entry = FlowEntry()
table_id = 0
flow_entry.set_flow_table_id(table_id)
flow_id = 16
flow_entry.set_flow_id(flow_id)
flow_entry.set_flow_priority(flow_priority = 1007)
flow_entry.set_flow_cookie(cookie=101)
flow_entry.set_flow_cookie_mask(cookie_mask=255)

# --- Instruction: 'Apply-action'
#     Action:      'Output' NORMAL
instruction = Instruction(instruction_order = 0)
action = DropAction(action_order = 0)
instruction.add_apply_action(action)
flow_entry.add_instruction(instruction)

# --- Match Fields: 
match = Match()    
match.set_eth_type(2048)
match.set_eth_src("00:00:00:11:23:ae")
match.set_eth_dst("ff:ff:29:01:19:61")
match.set_ipv4_src("17.1.2.3/8")
match.set_ipv4_dst("172.168.5.6/16")
match.set_ip_proto(6)
match.set_ip_dscp(2)
match.set_ip_ecn(2)    
match.set_tcp_src_port(25364)
match.set_tcp_dst_port(8080)
match.set_in_port(10)    
flow_entry.add_match(match)

# --- Program The Flow:
result = ofswitch.add_modify_flow(flow_entry)
status = result[0]    

# --- Retrieve The Flow:
print ("\n")    
print ("<<< Get configured flow from the Controller")    
result = ofswitch.get_configured_flow(table_id, flow_id)
flow = result[1]
print json.dumps(flow, indent=4)

About

Python library and sample apps and tools to work with Brocade SDN Controller RESTCONF interface. Scroll down for more info.

Resources

License

BSD-3-Clause, BSD-3-Clause licenses found

Licenses found

BSD-3-Clause
LICENSE
BSD-3-Clause
LICENSE.md

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 99.4%
  • Perl 0.6%