Example #1
0
    def setUp(self):
        odl = OpenDaylight()
        odl.setup['hostname'] = CONTROLLER
        odl.setup['username'] = USERNAME
        odl.setup['password'] = PASSWORD
        self.flow = OpenDaylightFlow(odl)
        self.node = OpenDaylightNode(odl)

        self.switch_id_1 = SWITCH_1

        self.odl_test_flow_1 = {
            u'actions': u'DROP',
            u'etherType': u'0x800',
            u'ingressPort': u'1',
            u'installInHw': u'true',
            u'name': u'odl-test-flow1',
            u'node': {
                u'@id': self.switch_id_1,
                u'@type': u'OF'
            },
            u'priority': u'500'
        }

        self.odl_test_flow_2 = {
            u'actions': u'DROP',
            u'etherType': u'0x800',
            u'ingressPort': u'2',
            u'installInHw': u'true',
            u'name': u'odl-test-flow2',
            u'node': {
                u'@id': self.switch_id_1,
                u'@type': u'OF'
            },
            u'priority': u'500'
        }
    def setUp(self):
        odl = OpenDaylight()
        odl.setup['hostname'] = CONTROLLER
        odl.setup['username'] = USERNAME
        odl.setup['password'] = PASSWORD
        self.flow = OpenDaylightFlow(odl)
        self.node = OpenDaylightNode(odl)

        self.switch_id_1 = SWITCH_1

        self.odl_test_flow_1 = {u'actions': u'DROP',
           u'etherType': u'0x800',
           u'ingressPort': u'1',
           u'installInHw': u'true',
           u'name': u'odl-test-flow1',
           u'node': {u'@id': self.switch_id_1, u'@type': u'OF'},
           u'priority': u'500'}

        self.odl_test_flow_2 = {u'actions': u'DROP',
           u'etherType': u'0x800',
           u'ingressPort': u'2',
           u'installInHw': u'true',
           u'name': u'odl-test-flow2',
           u'node': {u'@id': self.switch_id_1, u'@type': u'OF'},
           u'priority': u'500'}
Example #3
0
# Author: Nabil Maadarani
#
# This file allows users to add a flow

from OpenDaylight import OpenDaylight
from OpenDaylight import OpenDaylightFlow

# Initiate connection to the ODL controller
odl = OpenDaylight()
odl.setup[
    'hostname'] = '127.0.0.1'  # Replace with the ODL Controller IP addresss
odl.setup['username'] = '******'  # User ID to login to the ODL Controller
odl.setup['password'] = '******'  # Password to login to the ODL Controller

flow = OpenDaylightFlow(odl)

# User instructions
print('>> You are about to add a new flow')
flowName = 'sshFlow'
localIp = '10.0.0.1'  # Specific to the local host
remoteIp = '10.0.0.3'  # Specific to the remote host
dstPort = raw_input('>> Enter the port number: ')

if (dstPort == ''):
    # Build the local flow
    odl_test_flow1 = {
        'installInHw': 'true',
        'name': flowName + '1',
        'node': {
            'id': '00:00:00:00:00:00:00:01',
            'type': 'OF'
class TestSequenceFunctions(unittest.TestCase):
    """Tests for OpenDaylight

       At this point, tests for OpenDaylightFlow and OpenDaylightNode
       are intermingled.  These could be seperated out into seperate
       suites.
    """

    def setUp(self):
        odl = OpenDaylight()
        odl.setup['hostname'] = CONTROLLER
        odl.setup['username'] = USERNAME
        odl.setup['password'] = PASSWORD
        self.flow = OpenDaylightFlow(odl)
        self.node = OpenDaylightNode(odl)

        self.switch_id_1 = SWITCH_1

        self.odl_test_flow_1 = {u'actions': u'DROP',
           u'etherType': u'0x800',
           u'ingressPort': u'1',
           u'installInHw': u'true',
           u'name': u'odl-test-flow1',
           u'node': {u'@id': self.switch_id_1, u'@type': u'OF'},
           u'priority': u'500'}

        self.odl_test_flow_2 = {u'actions': u'DROP',
           u'etherType': u'0x800',
           u'ingressPort': u'2',
           u'installInHw': u'true',
           u'name': u'odl-test-flow2',
           u'node': {u'@id': self.switch_id_1, u'@type': u'OF'},
           u'priority': u'500'}


    def test_01_delete_flows(self):
        """Clean up from any previous test run, just delete these
            flows if they exist.
        """
        try:
            self.flow.delete(self.odl_test_flow_1['node']['@id'],
                             self.odl_test_flow_1['name'])
        except:
            pass

        try:
            self.flow.delete(self.odl_test_flow_2['node']['@id'],
                             self.odl_test_flow_2['name'])
        except:
            pass

    def test_10_add_flow(self):
        """Add a sample flow onto the controller
        """
        self.flow.add(self.odl_test_flow_1)
        self.assertEqual(self.flow.request.status_code, 201)

    def test_10_add_flow2(self):
        """Add a sample flow onto the controller
        """
        self.flow.add(self.odl_test_flow_2)
        self.assertEqual(self.flow.request.status_code, 201)

    def test_15_add_flow2(self):
        """Add a duplicate flow onto the controller
        """
        try:
            self.flow.add(self.odl_test_flow_2)
        except OpenDaylightError:
            pass
        except e:
            self.fail('Unexpected exception thrown:', e)
        else:
            self.fail('Expected Exception not thrown')

    def test_20_get_flow(self):
        """Retrieve the specific flow back from the controller
        """
        self.flow.get(node_id=self.switch_id_1, flow_name='odl-test-flow1')
        self.assertEqual(self.flow.flows, self.odl_test_flow_1)
        self.assertEqual(self.flow.request.status_code, 200)

    def test_20_get_flow2(self):
        """Retrieve the specific flow back from the controller
        """
        self.flow.get(node_id=self.switch_id_1, flow_name='odl-test-flow1')
        self.assertEqual(self.flow.flows, self.odl_test_flow_1)
        self.assertEqual(self.flow.request.status_code, 200)


    def test_30_get_all_switch_flows(self):
        """Retrieve all flows from this switch back from the controller
        """
        self.flow.get(node_id=self.switch_id_1)
        self.assertTrue(self.odl_test_flow_1 in self.flow.flows)
        self.assertTrue(self.odl_test_flow_2 in self.flow.flows)
        self.assertEqual(self.flow.request.status_code, 200)

    def test_30_get_all_flows(self):
        """Retrieve all flows back from the controller
        """
        self.flow.get()
        self.assertTrue(self.odl_test_flow_1 in self.flow.flows)
        self.assertTrue(self.odl_test_flow_2 in self.flow.flows)
        self.assertEqual(self.flow.request.status_code, 200)

    def test_30_get_flows_invalid_switch(self):
        """Try to get a flow from a non-existant switch
        """
        try:
            # This dpid is specifically chosen figuring that it 
            # would not be in use in a production system.  Plus, I
            # simply just like the number 53.
            self.flow.get(node_id='53:53:53:53:53:53:53:53')
        except OpenDaylightError:
            pass
        except e:
            self.fail('Unexpected exception thrown:', e)
        else:
            self.fail('Expected Exception not thrown')

    def test_40_get_flows_invalid_flowname(self):
        """Try to get a flow that does not exist.
        """
        try:
            self.flow.get(node_id=self.switch_id_1, flow_name='foo-foo-foo-bar')
        except OpenDaylightError:
            pass
        except e:
            self.fail('Unexpected exception thrown:', e)
        else:
            self.fail('Expected Exception not thrown')

    def test_50_delete_flow(self):
        """Delete flow 1.
        """
        self.flow.delete(self.odl_test_flow_1['node']['@id'],
                         self.odl_test_flow_1['name'])
        self.assertEqual(self.flow.request.status_code, 200)


    def test_51_deleted_flow_get(self):
        """Verify that the deleted flow does not exist.
        """
        try:
            self.flow.get(node_id=self.switch_id_1, flow_name='odl-test-flow1')
        except OpenDaylightError:
            pass
        except e:
            self.fail('Unexpected exception thrown:', e)
        else:
            self.fail('Expected Exception not thrown')

    def test_55_delete_flow2(self):
        """Delete flow 2
        """
        self.flow.delete(self.odl_test_flow_2['node']['@id'],
                         self.odl_test_flow_2['name'])
        self.assertEqual(self.flow.request.status_code, 200)


    #TODO:  Add invalid flow that has a bad port 
    #TODO:  Add invalid flow that has a non-existant switch 
    #TODO:  Add invalid flow that has an invalid switch name (non-hexadecimal), 
    #       see https://bugs.opendaylight.org/show_bug.cgi?id=27

    def test_60_get_all_nodes(self):
        """Get all of the nodes on the controller

           TODO: verify that SWITCH_1 is contained in the response
        """
        self.node.get_nodes()
        self.assertEqual(self.node.request.status_code, 200)

    def test_60_get_node_connector(self):
        """Retrieve a list of all the node connectors and their properties 
           in a given node 

           TODO: verify that SWITCH_1 is contained in the response
        """
        self.node.get_node_connectors(SWITCH_1)
        self.assertEqual(self.node.request.status_code, 200)


    def test_60_get_bad_node_connector(self):
        """Retrieve a list of all the node connectors and their properties 
           in a given node for a node that does not exist
        """
        try:
            self.node.get_node_connectors('53:53:53:53:53:53:53:53')
        except OpenDaylightError:
            pass
        except e:
            self.fail('Unexpected exception thrown:', e)
        else:
            self.fail('Expected Exception not thrown')


    def test_60_save(self):
        """Save the switch configurations.  
            It's not clear that this can be easily tested, so we just
            see if this call works or not based on the http status code.
        """
        self.node.save()
        self.assertEqual(self.node.request.status_code, 200)
Example #5
0
# Author: Nabil Maadarani
#
# This file allows users to add a flow

from OpenDaylight import OpenDaylight
from OpenDaylight import OpenDaylightFlow

# Initiate connection to the ODL controller
odl = OpenDaylight()
odl.setup['hostname'] = '127.0.0.1' # Replace with the ODL Controller IP addresss
odl.setup['username'] = '******' # User ID to login to the ODL Controller
odl.setup['password'] = '******' # Password to login to the ODL Controller

flow = OpenDaylightFlow(odl)

# User instructions
print('>> You are about to add a new flow')
flowName = 'sshFlow'
localIp = '10.0.0.1' # Specific to the local host
remoteIp = '10.0.0.3' # Specific to the remote host
dstPort = raw_input('>> Enter the port number: ')

if(dstPort == ''):
	# Build the local flow
	odl_test_flow1 = {
		   'installInHw': 'true',
		   'name': flowName + '1',
		   'node': {'id': '00:00:00:00:00:00:00:01', 'type': 'OF'}, # Specific to the node being used
		   'priority': '500',
		   'nwSrc' : localIp,
		   'nwDst' : remoteIp,
# Author: Nabil Maadarani
#
# This file allows the deletion of an existing flow

from OpenDaylight import OpenDaylight
from OpenDaylight import OpenDaylightFlow

# Initiate connection to the ODL controller
odl = OpenDaylight()
odl.setup['hostname'] = '127.0.0.1' # Replace with the ODL Controller IP addresss
odl.setup['username'] = '******' # User ID to login to the ODL Controller
odl.setup['password'] = '******' # Password to login to the ODL Controller

flow = OpenDaylightFlow(odl)

# User instructions
print('>> WARNING... You are about to remove a flow!')
flowName = raw_input('>> Enter the flow name: ')

# Delete flows
flow.delete('00:00:00:00:00:00:00:01', flowName + '1') # The first field is the ID of the node being used
flow.delete('00:00:00:00:00:00:00:02', flowName + '2') # The first field is the ID of the node being used

# Print success message
print('********************************')
print('>> SUCCESS... The following flows have been deleted:')
print('>> ' + flowName + '1 on switch #1')
print('>> ' + flowName + '2 on switch #2')
print('********************************')
Example #7
0
class TestSequenceFunctions(unittest.TestCase):
    """Tests for OpenDaylight

       At this point, tests for OpenDaylightFlow and OpenDaylightNode
       are intermingled.  These could be seperated out into seperate
       suites.
    """
    def setUp(self):
        odl = OpenDaylight()
        odl.setup['hostname'] = CONTROLLER
        odl.setup['username'] = USERNAME
        odl.setup['password'] = PASSWORD
        self.flow = OpenDaylightFlow(odl)
        self.node = OpenDaylightNode(odl)

        self.switch_id_1 = SWITCH_1

        self.odl_test_flow_1 = {
            u'actions': u'DROP',
            u'etherType': u'0x800',
            u'ingressPort': u'1',
            u'installInHw': u'true',
            u'name': u'odl-test-flow1',
            u'node': {
                u'@id': self.switch_id_1,
                u'@type': u'OF'
            },
            u'priority': u'500'
        }

        self.odl_test_flow_2 = {
            u'actions': u'DROP',
            u'etherType': u'0x800',
            u'ingressPort': u'2',
            u'installInHw': u'true',
            u'name': u'odl-test-flow2',
            u'node': {
                u'@id': self.switch_id_1,
                u'@type': u'OF'
            },
            u'priority': u'500'
        }

    def test_01_delete_flows(self):
        """Clean up from any previous test run, just delete these
            flows if they exist.
        """
        try:
            self.flow.delete(self.odl_test_flow_1['node']['@id'],
                             self.odl_test_flow_1['name'])
        except:
            pass

        try:
            self.flow.delete(self.odl_test_flow_2['node']['@id'],
                             self.odl_test_flow_2['name'])
        except:
            pass

    def test_10_add_flow(self):
        """Add a sample flow onto the controller
        """
        self.flow.add(self.odl_test_flow_1)
        self.assertEqual(self.flow.request.status_code, 201)

    def test_10_add_flow2(self):
        """Add a sample flow onto the controller
        """
        self.flow.add(self.odl_test_flow_2)
        self.assertEqual(self.flow.request.status_code, 201)

    def test_15_add_flow2(self):
        """Add a duplicate flow onto the controller
        """
        try:
            self.flow.add(self.odl_test_flow_2)
        except OpenDaylightError:
            pass
        except e:
            self.fail('Unexpected exception thrown:', e)
        else:
            self.fail('Expected Exception not thrown')

    def test_20_get_flow(self):
        """Retrieve the specific flow back from the controller
        """
        self.flow.get(node_id=self.switch_id_1, flow_name='odl-test-flow1')
        self.assertEqual(self.flow.flows, self.odl_test_flow_1)
        self.assertEqual(self.flow.request.status_code, 200)

    def test_20_get_flow2(self):
        """Retrieve the specific flow back from the controller
        """
        self.flow.get(node_id=self.switch_id_1, flow_name='odl-test-flow1')
        self.assertEqual(self.flow.flows, self.odl_test_flow_1)
        self.assertEqual(self.flow.request.status_code, 200)

    def test_30_get_all_switch_flows(self):
        """Retrieve all flows from this switch back from the controller
        """
        self.flow.get(node_id=self.switch_id_1)
        self.assertTrue(self.odl_test_flow_1 in self.flow.flows)
        self.assertTrue(self.odl_test_flow_2 in self.flow.flows)
        self.assertEqual(self.flow.request.status_code, 200)

    def test_30_get_all_flows(self):
        """Retrieve all flows back from the controller
        """
        self.flow.get()
        self.assertTrue(self.odl_test_flow_1 in self.flow.flows)
        self.assertTrue(self.odl_test_flow_2 in self.flow.flows)
        self.assertEqual(self.flow.request.status_code, 200)

    def test_30_get_flows_invalid_switch(self):
        """Try to get a flow from a non-existant switch
        """
        try:
            # This dpid is specifically chosen figuring that it
            # would not be in use in a production system.  Plus, I
            # simply just like the number 53.
            self.flow.get(node_id='53:53:53:53:53:53:53:53')
        except OpenDaylightError:
            pass
        except e:
            self.fail('Unexpected exception thrown:', e)
        else:
            self.fail('Expected Exception not thrown')

    def test_40_get_flows_invalid_flowname(self):
        """Try to get a flow that does not exist.
        """
        try:
            self.flow.get(node_id=self.switch_id_1,
                          flow_name='foo-foo-foo-bar')
        except OpenDaylightError:
            pass
        except e:
            self.fail('Unexpected exception thrown:', e)
        else:
            self.fail('Expected Exception not thrown')

    def test_50_delete_flow(self):
        """Delete flow 1.
        """
        self.flow.delete(self.odl_test_flow_1['node']['@id'],
                         self.odl_test_flow_1['name'])
        self.assertEqual(self.flow.request.status_code, 200)

    def test_51_deleted_flow_get(self):
        """Verify that the deleted flow does not exist.
        """
        try:
            self.flow.get(node_id=self.switch_id_1, flow_name='odl-test-flow1')
        except OpenDaylightError:
            pass
        except e:
            self.fail('Unexpected exception thrown:', e)
        else:
            self.fail('Expected Exception not thrown')

    def test_55_delete_flow2(self):
        """Delete flow 2
        """
        self.flow.delete(self.odl_test_flow_2['node']['@id'],
                         self.odl_test_flow_2['name'])
        self.assertEqual(self.flow.request.status_code, 200)

    #TODO:  Add invalid flow that has a bad port
    #TODO:  Add invalid flow that has a non-existant switch
    #TODO:  Add invalid flow that has an invalid switch name (non-hexadecimal),
    #       see https://bugs.opendaylight.org/show_bug.cgi?id=27

    def test_60_get_all_nodes(self):
        """Get all of the nodes on the controller

           TODO: verify that SWITCH_1 is contained in the response
        """
        self.node.get_nodes()
        self.assertEqual(self.node.request.status_code, 200)

    def test_60_get_node_connector(self):
        """Retrieve a list of all the node connectors and their properties 
           in a given node 

           TODO: verify that SWITCH_1 is contained in the response
        """
        self.node.get_node_connectors(SWITCH_1)
        self.assertEqual(self.node.request.status_code, 200)

    def test_60_get_bad_node_connector(self):
        """Retrieve a list of all the node connectors and their properties 
           in a given node for a node that does not exist
        """
        try:
            self.node.get_node_connectors('53:53:53:53:53:53:53:53')
        except OpenDaylightError:
            pass
        except e:
            self.fail('Unexpected exception thrown:', e)
        else:
            self.fail('Expected Exception not thrown')

    def test_60_save(self):
        """Save the switch configurations.  
            It's not clear that this can be easily tested, so we just
            see if this call works or not based on the http status code.
        """
        self.node.save()
        self.assertEqual(self.node.request.status_code, 200)