Example #1
0
    def deleteRule(logger, source, table, version=None):
        """This function deletes a rule

        Args:
            logger
            source  -   select the source prefix to match. 
            table   -   the routing table identifier to lookup if the rule selector matches. TABLEID may be a number or a string
            version -   IPv4 or IPv6 as an integer, 4 or 6
            
        Return:
            tuple (rc, stdout, stderr) 

        Raise:
            None
        """

        if version:
            if version == 4:
                return Command.executeIp(logger, IpConstant.IPV4,
                                         IpOption.RULE, IpAction.DELETE,
                                         IpConstant.FROM, source,
                                         IpConstant.TABLE, table)
            elif version == 6:
                return Command.executeIp(logger, IpConstant.IPV6,
                                         IpOption.RULE, IpAction.DELETE,
                                         IpConstant.FROM, source,
                                         IpConstant.TABLE, table)

        rc = Command.executeIp(logger, IpOption.RULE, IpAction.DELETE,
                               IpConstant.FROM, source, IpConstant.TABLE,
                               table)
        return rc
Example #2
0
    def deleteAddress(logger, address, device, version=None):
        """This function deletes an IP address

        Args:
            logger
            address - IP address to dettach
            device - the name of the device to delete the address from
            version - IPv4 or IPv6 as an integer, 4 or 6
            
        Return:
            tuple (rc, stdout, stderr) 

        Raise:
            None
        """

        if version:
            if version == 4:
                return Command.executeIp(logger, IpConstant.IPV4, IpOption.ADDRESS, IpAction.DELETE, 
                    address, IpConstant.DEV, device) 
            elif version == 6:
                return Command.executeIp(logger, IpConstant.IPV6, IpOption.ADDRESS, IpAction.DELETE, 
                    address, IpConstant.DEV, device) 

        rc =  Command.executeIp(logger, IpOption.ADDRESS, IpAction.DELETE, 
                    address, IpConstant.DEV, device)   
        return rc 
Example #3
0
    def flushRules(logger, table, version=None):
        """This function flushes all rules associated with the table

        Args:
            logger
            table   -   the routing table identifier to lookup if the rule selector matches. TABLEID may be a number or a string
            version -   IPv4 or IPv6 as an integer, 4 or 6
            
        Return:
            tuple (rc, stdout, stderr) 

        Raise:
            None
        """

        if version:
            if version == 4:
                return Command.executeIp(logger, IpConstant.IPV4,
                                         IpOption.RULE, IpAction.DELETE,
                                         IpConstant.TABLE, table)
            elif version == 6:
                return Command.executeIp(logger, IpConstant.IPV6,
                                         IpOption.RULE, IpAction.DELETE,
                                         IpConstant.TABLE, table)

        rc = Command.executeIp(logger, IpOption.RULE, IpAction.DELETE,
                               IpConstant.TABLE, table)
        return rc
Example #4
0
    def showRoutes(logger, table, version=None):
        """This function list all routes

        Args:
            logger
            table -     show the routes from this table
            
        Return:
            tuple (rc, stdout, stderr) 

        Raise:
            None

        """

        if version:
            if version == 4:
                return Command.executeIp(logger, IpConstant.IPV4,
                                         IpOption.ROUTE, IpAction.SHOW,
                                         IpConstant.TABLE, table)
            elif version == 6:
                return Command.executeIp(logger, IpConstant.IPV6,
                                         IpOption.ROUTE, IpAction.SHOW,
                                         IpConstant.TABLE, table)

        rc = Command.executeIp(logger, IpOption.ROUTE, IpAction.SHOW,
                               IpConstant.TABLE, table)

        return rc
Example #5
0
    def deleteRoute(logger, destination, gateway, table, version=None):
        """This function deletes an IP route

        Args:
            logger
            destination-the destination prefix of the route 
            gateway -   the address of the nexthop router.
            table -     the table to delete this route from. TABLEID may be a number or a string
            version -   IPv4 or IPv6 as an integer, 4 or 6
            
        Return:
            tuple (rc, stdout, stderr) 

        Raise:
            None
        """

        if version:
            if version == 4:
                return Command.executeIp(logger, IpConstant.IPV4,
                                         IpOption.ROUTE, IpAction.DELETE,
                                         destination, IpConstant.VIA, gateway,
                                         IpConstant.TABLE, table)
            elif version == 6:
                return Command.executeIp(logger, IpConstant.IPV6,
                                         IpOption.ROUTE, IpAction.DELETE,
                                         destination, IpConstant.VIA, gateway,
                                         IpConstant.TABLE, table)

        rc = Command.executeIp(logger, IpOption.ROUTE, IpAction.DELETE,
                               destination, IpConstant.VIA, gateway,
                               IpConstant.TABLE, table)
        return rc
Example #6
0
    def flushAddresses(logger, device, scope=None, version=None):
        """This function flushes all IP addresses assigned to a device

        Args:
            logger
            device - the name of the device to flush all addresses
            version - IPv4 or IPv6 as an integer, 4 or 6
            scope  -  the scope of the area where this address flush is valid: global, site, link, host
            
        Return:
            tuple (rc, stdout, stderr) 

        Raise:
            None
        """

        args = []

        if version:
            if version == 4:
                args.append(IpConstant.IPV4)
            elif version == 6:
                args.append(IpConstant.IPV6)

        args += [IpOption.ADDRESS, IpAction.FLUSH, IpConstant.DEV, device]

        if scope: args += [IpConstant.SCOPE, scope]

        option = args[0]
        cmd = args[1:]

        rc =  Command.executeIp(logger, option, *cmd)   
        return rc 
Example #7
0
    def showNeighboursByDevice(logger, device, version=None):
        """This function list neighbour entries attached to the given device

        Args:
            logger
            device  - device name
            version - IPv4 or IPv6 as an integer, 4 or 6
            
        Return:
            tuple (rc, stdout, stderr) 

        Raise:
            None
        """

        args = []

        if version:
            if version == 4:
                args.append(IpConstant.IPV4)
            elif version == 6:
                args.append(IpConstant.IPV6)

        args += [IpOption.NEIGHBOUR, IpAction.SHOW, IpConstant.DEV, device]

        option = args[0]
        cmd = args[1:]

        rc = Command.executeIp(logger, option, *cmd)
        return rc
Example #8
0
    def flushDefaultRoute(logger, table, version=None):
        """This function flushes an existing IP default route 

        Args:
            logger
            table -     the table to add this route to. TABLEID may be a number or a string
            version -   IPv4 or IPv6 as an integer, 4 or 6
            
        Return:
            tuple (rc, stdout, stderr) 

        Raise:
            None
        """

        args = []

        if version:
            if version == 4:
                args.append(IpConstant.IPV4)
            elif version == 6:
                args.append(IpConstant.IPV6)

        args += [IpOption.ROUTE, IpAction.FLUSH, IpConstant.DEFAULT]

        if table: args += [IpConstant.TABLE, table]

        option = args[0]
        cmd = args[1:]

        rc = Command.executeIp(logger, option, *cmd)
        return rc
Example #9
0
    def showNeighboursByDevice(logger, device, version=None):
        """This function list neighbour entries attached to the given device

        Args:
            logger
            device  - device name
            version - IPv4 or IPv6 as an integer, 4 or 6
            
        Return:
            tuple (rc, stdout, stderr) 

        Raise:
            None
        """

        args = []

        if version:
            if version == 4:
                args.append(IpConstant.IPV4)
            elif version == 6:
                args.append(IpConstant.IPV6)

        args += [IpOption.NEIGHBOUR, IpAction.SHOW, IpConstant.DEV, device]

        option = args[0]
        cmd = args[1:]

        rc =  Command.executeIp(logger, option, *cmd)   
        return rc 
Example #10
0
    def showNeighbours(logger, version=None):
        """This function list neighbour entries

        Args:
            logger
            version - IPv4 or IPv6 as an integer, 4 or 6
            
        Return:
            tuple (rc, stdout, stderr) 

        Raise:
            None
        """

        if version:
            if version == 4:
                return Command.executeIp(logger, IpConstant.IPV4, IpOption.NEIGHBOUR, IpAction.SHOW)   
            elif version == 6:
                return Command.executeIp(logger, IpConstant.IPV6, IpOption.NEIGHBOUR, IpAction.SHOW)   

        rc =  Command.executeIp(logger, IpOption.NEIGHBOUR, IpAction.SHOW)   
        return rc
Example #11
0
    def replaceRoute(logger,
                     destination,
                     gateway=None,
                     table=None,
                     device=None,
                     version=None,
                     scope=None,
                     metric=None,
                     src=None):
        """This function adds a new IP route or changes an existing IP route

        Args:
            logger
            destination-the destination prefix of the route 
            gateway -   the address of the nexthop router.
            table -     the table to add this route to. TABLEID may be a number or a string
            device -    the name specifies network device
            version -   IPv4 or IPv6 as an integer, 4 or 6
            scope -     the scope of the area where this address is valid: global, site, link, host
            metric -    the preference value of the route. NUMBER is an arbitrary 32bit number.
            src -       the source address to prefer when sending to the destinations covered by the route prefix
            
        Return:
            tuple (rc, stdout, stderr) 

        Raise:
            None
        """

        args = []

        if version:
            if version == 4:
                args.append(IpConstant.IPV4)
            elif version == 6:
                args.append(IpConstant.IPV6)

        args += [IpOption.ROUTE, IpAction.REPLACE, destination]

        if gateway: args += [IpConstant.VIA, gateway]
        if device: args += [IpConstant.DEV, device]
        if table: args += [IpConstant.TABLE, table]
        if scope: args += [IpConstant.SCOPE, scope]
        if metric: args += [IpConstant.METRIC, str(metric)]
        if src: args += [IpConstant.SRC, src]

        option = args[0]
        cmd = args[1:]

        rc = Command.executeIp(logger, option, *cmd)
        return rc
Example #12
0
    def showRules(logger, version=None):
        """This function list all rules

        Args:
            logger
            
        Return:
            tuple (rc, stdout, stderr) 

        Raise:
            None
        """

        if version:
            if version == 4:
                return Command.executeIp(logger, IpConstant.IPV4,
                                         IpOption.RULE, IpAction.SHOW)
            elif version == 6:
                return Command.executeIp(logger, IpConstant.IPV6,
                                         IpOption.RULE, IpAction.SHOW)

        rc = Command.executeIp(logger, IpOption.RULE, IpAction.SHOW)
        return rc
Example #13
0
    def showAddresses(logger):
        """This function list all protocol addresseses

        Args:
            logger
            
        Return:
            tuple (rc, stdout, stderr) 

        Raise:
            None
        """
        rc =  Command.executeIp(logger, IpOption.ADDRESS, IpAction.SHOW)   
        return rc 
Example #14
0
    def showNeighbours(logger, version=None):
        """This function list neighbour entries

        Args:
            logger
            version - IPv4 or IPv6 as an integer, 4 or 6
            
        Return:
            tuple (rc, stdout, stderr) 

        Raise:
            None
        """

        if version:
            if version == 4:
                return Command.executeIp(logger, IpConstant.IPV4,
                                         IpOption.NEIGHBOUR, IpAction.SHOW)
            elif version == 6:
                return Command.executeIp(logger, IpConstant.IPV6,
                                         IpOption.NEIGHBOUR, IpAction.SHOW)

        rc = Command.executeIp(logger, IpOption.NEIGHBOUR, IpAction.SHOW)
        return rc
Example #15
0
    def showDevices(logger):
        """This function list all devices

        Args:
            logger
            
        Return:
            tuple (rc, stdout, stderr) 

        Raise:
            None
        """

        rc =  Command.executeIp(logger, IpOption.LINK, IpAction.SHOW)   
        return rc 
Example #16
0
    def showAddress(logger, device):
        """This function list an device protocol addresseses

        Args:
            logger
            device - the name of the device to show
            
        Return:
            tuple (rc, stdout, stderr) 

        Raise:
            None
        """
        rc =  Command.executeIp(logger, IpOption.ADDRESS, IpAction.SHOW,
                                    IpConstant.DEV, device)   
        return rc 
Example #17
0
    def showDeviceStatistics(logger, device):
        """This function shows a device statistics

        Args:
            logger
            device - the name specifies network device to show
            
        Return:
            tuple (rc, stdout, stderr) 

        Raise:
            None
        """

        rc =  Command.executeIp(logger, IpOption.LINK, IpLink.STATISTICS_OPTION, IpAction.SHOW,
                                    IpConstant.DEV, device)   
        return rc 
Example #18
0
    def activateDevice(logger, device):
        """This function change the state of the device to UP

        Args:
            logger
            device - the name specifies network device to operate on
            
        Return:
            tuple (rc, stdout, stderr) 

        Raise:
            None
        """

        rc =  Command.executeIp(logger, IpOption.LINK, IpAction.SET, 
                                    device, IpConstant.UP)   
        return rc 
Example #19
0
    def renameDevice(logger, device, name):
        """This function change the name of the device
        Note: This operation is not recommended if the device is running or has some addresses already configured

        Args:
            logger
            device - the name specifies network device to rename
            name   - change the name of the device
            
        Return:
            tuple (rc, stdout, stderr) 

        Raise:
            None
        """

        rc =  Command.executeIp(logger, IpOption.LINK, IpAction.SET, 
                                    IpConstant.DEV, device, IpConstant.NAME, name)   
        return rc 
Example #20
0
    def flushRoutes(logger,
                    table=None,
                    device=None,
                    version=None,
                    scope=None,
                    proto=None):
        """This function flushes all IP routes assigned to a device

        Args:
            logger
            table -     the table to add this route to. TABLEID may be a number or a string
            device -    the name specifies network device
            version -   IPv4 or IPv6 as an integer, 4 or 6
            scope -     the scope of the area where this address is valid: global, site, link, host
            proto -     the routing protocol identifier of this route: kernel, boot, static, etc.
            
        Return:
            tuple (rc, stdout, stderr) 

        Raise:
            None
        """

        args = []

        if version:
            if version == 4:
                args.append(IpConstant.IPV4)
            elif version == 6:
                args.append(IpConstant.IPV6)

        args += [IpOption.ROUTE, IpAction.FLUSH]

        if device: args += [IpConstant.DEV, device]
        if table: args += [IpConstant.TABLE, table]
        if scope: args += [IpConstant.SCOPE, scope]
        if proto: args += [IpConstant.PROTO, proto]

        option = args[0]
        cmd = args[1:]

        rc = Command.executeIp(logger, option, *cmd)
        return rc