コード例 #1
0
 def _check_link_state(self, LinkUpTimeout):
     self._IxNetwork.info('Checking virtual port link states')
     view = StatViewAssistant(self._IxNetwork,
                              'Port Statistics',
                              Timeout=LinkUpTimeout)
     view.AddRowFilter('Port Name', StatViewAssistant.REGEX,
                       self._get_name_regex())
     view.CheckCondition('Link State',
                         StatViewAssistant.REGEX,
                         '^Link Up$',
                         Timeout=LinkUpTimeout)
コード例 #2
0
    def test_cannot_find_invalid_view_name(self, mock_request):
        test_platform = TestPlatform('127.0.0.1',
                                     rest_port=11009,
                                     platform='windows')

        # use the default session and get the root node of the hierarchy
        ixnetwork = test_platform.Sessions.find().Ixnetwork

        try:
            StatViewAssistant(ixnetwork, 'Port Stattics', Timeout=5)
        except NotFoundError as e:
            ixnetwork.info(e)
コード例 #3
0
    ixNetwork.Globals.Licensing.LicensingServers = licenseServerIp
    ixNetwork.Globals.Licensing.Mode = licenseMode
    ixNetwork.Globals.Licensing.Tier = licenseTier

    # Assign ports
    testPorts = []
    vportList = [vport.href for vport in ixNetwork.Vport.find()]
    for port in portList:
        testPorts.append(dict(Arg1=port[0], Arg2=port[1], Arg3=port[2]))

    ixNetwork.AssignPorts(testPorts, [], vportList, forceTakePortOwnership)

    ixNetwork.StartAllProtocols(Arg1='sync')

    ixNetwork.info('Verify protocol sessions\n')
    protocolsSummary = StatViewAssistant(ixNetwork, 'Protocols Summary')
    protocolsSummary.CheckCondition('Sessions Not Started',
                                    StatViewAssistant.EQUAL, 0)
    protocolsSummary.CheckCondition('Sessions Down', StatViewAssistant.EQUAL,
                                    0)
    ixNetwork.info(protocolsSummary)

    # Get the Traffic Item name for getting Traffic Item statistics.
    trafficItem = ixNetwork.Traffic.TrafficItem.find()[0]

    trafficItem.Generate()
    ixNetwork.Traffic.Apply()
    ixNetwork.Traffic.Start()

    # StatViewAssistant could also filter by regex, LESS_THAN, GREATER_THAN, EQUAL.
    # Examples:
コード例 #4
0
 def StatViewAssistant(self, ViewName, Timeout=180, LocalCsvStorage=None):
     """Get an instance of the StatViewAssistant class
     """
     return StatViewAssistant(self._ixnetwork, ViewName, Timeout, LocalCsvStorage)
コード例 #5
0
ファイル: vxlanNgpf.py プロジェクト: sar772004/IxNetwork
    vxlanEthernet2.EnableVlans.Single(True)

    vxlanEthernet2.Vlan.find()[0].VlanId.Increment(start_value=101,
                                                   step_value=0)

    ixNetwork.info('Create IPv4 for VxLAN')
    vxlanIpv4 = vxlanEthernet2.Ipv4.add(Name='VxLAN-IPv4-2')
    vxlanIpv4.Address.Increment(start_value='10.1.3.1', step_value='0.0.0.0')
    vxlanIpv4.GatewayIp.Increment(start_value='10.1.1.1', step_value='0.0.0.0')
    vxlanIpv4.Prefix.Single(16)
    vxlanIpv4.ResolveGateway.Single(True)

    ixNetwork.StartAllProtocols(Arg1='sync')

    ixNetwork.info('Verify protocol sessions')
    protocolsSummary = StatViewAssistant(ixNetwork, 'Protocols Summary')
    protocolsSummary.CheckCondition('Sessions Not Started',
                                    StatViewAssistant.EQUAL, 0)
    protocolsSummary.CheckCondition('Sessions Down', StatViewAssistant.EQUAL,
                                    0)
    ixNetwork.info(protocolsSummary)

    ixNetwork.info('Create Traffic Item')
    trafficItem = ixNetwork.Traffic.TrafficItem.add(Name='VxLAN traffic',
                                                    BiDirectional=False,
                                                    TrafficType='ipv4')

    ixNetwork.info('Add flow group')
    trafficItem.EndpointSet.add(Sources=topology1, Destinations=topology2)

    # Note: A Traffic Item could have multiple EndpointSets (Flow groups).
コード例 #6
0
    testPorts = []
    vportList = [vport.href for vport in ixNetwork.Vport.find()]
    for port in portList:
        testPorts.append(dict(Arg1=port[0], Arg2=port[1], Arg3=port[2]))

    ixNetwork.AssignPorts(testPorts, [], vportList, forceTakePortOwnership)

    for vport in ixNetwork.Vport.find():
        if vport.Type == 'novusTenGigLan':
            vport.L1Config.NovusTenGigLan.Media = portMedia

    if verifyNgpfIsLayer3:
        ixNetwork.StartAllProtocols(Arg1='sync')

        ixNetwork.info('Verify protocol sessions\n')
        protocolsSummary = StatViewAssistant(ixNetwork, 'Protocols Summary')
        protocolsSummary.CheckCondition('Sessions Not Started',
                                        StatViewAssistant.EQUAL, 0)
        protocolsSummary.CheckCondition('Sessions Down',
                                        StatViewAssistant.EQUAL, 0)
        ixNetwork.info(protocolsSummary)

    # Create a timestamp for test result files.
    # To append a timestamp in the CSV result files so existing result files won't get overwritten.
    timestamp = Timestamp()

    # These are all the RFC tests to search for in the saved config file.
    for rfcTest in [
            ixNetwork.QuickTest.Rfc2544frameLoss.find(),
            ixNetwork.QuickTest.Rfc2544throughput.find(),
            ixNetwork.QuickTest.Rfc2544back2back.find(),
コード例 #7
0
"""

from ixnetwork_restpy.testplatform.testplatform import TestPlatform
from ixnetwork_restpy.assistants.statistics.statviewassistant import StatViewAssistant
from ixnetwork_restpy.errors import *


# connect to a windows test platform using the default api server rest port
test_platform = TestPlatform('127.0.0.1', rest_port=11009, platform='windows')

# use the default session and get the root node of the hierarchy
ixnetwork = test_platform.Sessions.find().Ixnetwork

ixnetwork.info('negative test')
try:
    StatViewAssistant(ixnetwork, 'my test view', Timeout=5)
except NotFoundError as e:
    ixnetwork.info(e)

# get a list of all current statistic views that can be used in the StatViewAssistant
print(StatViewAssistant.GetViewNames(ixnetwork))

# create a stat view assistant for a statistics view
port_statistics = StatViewAssistant(ixnetwork, 'Port Statistics')

# print all the rows for a statistics view
print(port_statistics)

# add a filter so that only a single row is retrieved
port_statistics.AddRowFilter('Port Name', StatViewAssistant.REGEX, 'Port 1$')
print(port_statistics)
コード例 #8
0
    ipv4DstFieldObj = ipv4StackObj.Field.find(DisplayName='Destination Address')
    ipv4DstFieldObj.ValueType = 'increment'
    ipv4DstFieldObj.StartValue = "1.1.1.2"
    ipv4DstFieldObj.StepValue = "0.0.0.1"
    ipv4DstFieldObj.CountValue = 1

    trafficItem.Generate()
    ixNetwork.Traffic.Apply()
    ixNetwork.Traffic.Start()

    # StatViewAssistant could also filter by REGEX, LESS_THAN, GREATER_THAN, EQUAL. 
    # Examples:
    #    flowStatistics.AddRowFilter('Port Name', StatViewAssistant.REGEX, '^Port 1$')
    #    flowStatistics.AddRowFilter('Tx Frames', StatViewAssistant.LESS_THAN, 50000)

    flowStatistics = StatViewAssistant(ixNetwork, 'Flow Statistics')
    ixNetwork.info('{}\n'.format(flowStatistics))

    for rowNumber,flowStat in enumerate(flowStatistics.Rows):
        ixNetwork.info('\n\nSTATS: {}\n\n'.format(flowStat))
        ixNetwork.info('\nRow:{}  TxPort:{}  RxPort:{}  TxFrames:{}  RxFrames:{}\n'.format(
            rowNumber, flowStat['Tx Port'], flowStat['Rx Port'],
            flowStat['Tx Frames'], flowStat['Rx Frames']))

    trafficItemStatistics = StatViewAssistant(ixNetwork, 'Traffic Item Statistics')
    ixNetwork.info('{}\n'.format(trafficItemStatistics))
    
    # Get the statistic values
    txFrames = trafficItemStatistics.Rows[0]['Tx Frames']
    rxFrames = trafficItemStatistics.Rows[0]['Rx Frames']
    ixNetwork.info('Traffic Item Stats:\n\tTxFrames: {}  RxFrames: {}\n'.format(txFrames, rxFrames))
コード例 #9
0
ファイル: bgpNgpf.py プロジェクト: wengm/IxNetwork
def main():
    logging.basicConfig(filename='../ansible.log', level=logging.DEBUG)

    # Define the available arguments/parameters that a user can pass to this module.
    params = {
        'apiServerIp': {
            'type': 'str',
            'required': True,
            'default': None
        },
        'apiServerIpPort': {
            'type': 'int',
            'required': False,
            'default': 11009
        },
        'username': {
            'type': 'str',
            'required': False,
            'default': 'admin',
            'no_log': False
        },
        'password': {
            'type': 'str',
            'required': False,
            'default': 'admin',
            'no_log': False
        },
        'licenseServerIp': {
            'type': 'list',
            'required': True,
            'default': None
        },
        'licenseMode': {
            'type': 'str',
            'required': True,
            'default': None
        },
        'licenseTier': {
            'type': 'str',
            'required': False,
            'default': 'tier3'
        },
        'portList': {
            'type': 'list',
            'required': True,
            'default': None
        },
        'forceTakePortOwnership': {
            'type': 'bool',
            'required': False,
            'default': True
        },
        'debugMode': {
            'type': 'str',
            'required': False,
            'default': False
        },
    }

    result = dict(changed=False, message='')
    module = AnsibleModule(argument_spec=params, supports_check_mode=True)

    if module.check_mode:
        module.exit_json(**result)

    module.params['name'] = 'Custom Ansible module for NGPF BGP configuration'

    try:

        testPlatform = TestPlatform(ip_address=module.params['apiServerIp'],
                                    rest_port=module.params['apiServerIpPort'],
                                    log_file_name='restpy.log')

        # Console output verbosity: None|request|'request response'
        testPlatform.Trace = 'request_response'

        testPlatform.Authenticate(module.params['username'],
                                  module.params['password'])
        session = testPlatform.Sessions.add()
        ixNetwork = session.Ixnetwork

        ixNetwork.NewConfig()

        ixNetwork.Globals.Licensing.LicensingServers = module.params[
            'licenseServerIp']
        ixNetwork.Globals.Licensing.Mode = module.params['licenseMode']
        ixNetwork.Globals.Licensing.Tier = module.params['licenseTier']

        # Create vports and name them so you could get the vports by the name when creating Topology.
        vport1 = ixNetwork.Vport.add(Name='Port1')
        vport2 = ixNetwork.Vport.add(Name='Port2')

        # Assign ports
        testPorts = []
        vportList = [vport.href for vport in ixNetwork.Vport.find()]
        for port in module.params['portList']:
            testPorts.append(dict(Arg1=port[0], Arg2=port[1], Arg3=port[2]))

        ixNetwork.AssignPorts(testPorts, [], vportList,
                              module.params['forceTakePortOwnership'])

        ixNetwork.info('Creating Topology Group 1')
        topology1 = ixNetwork.Topology.add(Name='Topology 1', Ports=vport1)
        deviceGroup1 = topology1.DeviceGroup.add(Name='DG1', Multiplier='1')
        ethernet1 = deviceGroup1.Ethernet.add(Name='Eth1')
        ethernet1.Mac.Increment(start_value='00:01:01:01:00:01',
                                step_value='00:00:00:00:00:01')
        ethernet1.EnableVlans.Single(True)

        ixNetwork.info('Configuring vlanID')
        vlanObj = ethernet1.Vlan.find()[0].VlanId.Increment(start_value=103,
                                                            step_value=0)

        ixNetwork.info('Configuring IPv4')
        ipv4 = ethernet1.Ipv4.add(Name='Ipv4')
        ipv4.Address.Increment(start_value='1.1.1.1', step_value='0.0.0.1')
        ipv4.GatewayIp.Increment(start_value='1.1.1.2', step_value='0.0.0.0')

        ixNetwork.info('Configuring BgpIpv4Peer 1')
        bgp1 = ipv4.BgpIpv4Peer.add(Name='Bgp1')
        bgp1.DutIp.Increment(start_value='1.1.1.2', step_value='0.0.0.0')
        bgp1.Type.Single('internal')
        bgp1.LocalAs2Bytes.Increment(start_value=101, step_value=0)

        ixNetwork.info('Configuring Network Group 1')
        networkGroup1 = deviceGroup1.NetworkGroup.add(Name='BGP-Routes1',
                                                      Multiplier='100')
        ipv4PrefixPool = networkGroup1.Ipv4PrefixPools.add(
            NumberOfAddresses='1')
        ipv4PrefixPool.NetworkAddress.Increment(start_value='10.10.0.1',
                                                step_value='0.0.0.1')
        ipv4PrefixPool.PrefixLength.Single(32)

        topology2 = ixNetwork.Topology.add(Name='Topology 2', Ports=vport2)
        deviceGroup2 = topology2.DeviceGroup.add(Name='DG2', Multiplier='1')

        ethernet2 = deviceGroup2.Ethernet.add(Name='Eth2')
        ethernet2.Mac.Increment(start_value='00:01:01:02:00:01',
                                step_value='00:00:00:00:00:01')
        ethernet2.EnableVlans.Single(True)

        ixNetwork.info('Configuring vlanID')
        vlanObj = ethernet2.Vlan.find()[0].VlanId.Increment(start_value=103,
                                                            step_value=0)

        ixNetwork.info('Configuring IPv4 2')
        ipv4 = ethernet2.Ipv4.add(Name='Ipv4-2')
        ipv4.Address.Increment(start_value='1.1.1.2', step_value='0.0.0.1')
        ipv4.GatewayIp.Increment(start_value='1.1.1.1', step_value='0.0.0.0')

        ixNetwork.info('Configuring BgpIpv4Peer 2')
        bgp2 = ipv4.BgpIpv4Peer.add(Name='Bgp2')
        bgp2.DutIp.Increment(start_value='1.1.1.1', step_value='0.0.0.0')
        bgp2.Type.Single('internal')
        bgp2.LocalAs2Bytes.Increment(start_value=101, step_value=0)

        ixNetwork.info('Configuring Network Group 2')
        networkGroup2 = deviceGroup2.NetworkGroup.add(Name='BGP-Routes2',
                                                      Multiplier='100')
        ipv4PrefixPool = networkGroup2.Ipv4PrefixPools.add(
            NumberOfAddresses='1')
        ipv4PrefixPool.NetworkAddress.Increment(start_value='20.20.0.1',
                                                step_value='0.0.0.1')
        ipv4PrefixPool.PrefixLength.Single(32)

        ixNetwork.StartAllProtocols(Arg1='sync')

        ixNetwork.info('Verify protocol sessions\n')
        protocolsSummary = StatViewAssistant(ixNetwork, 'Protocols Summary')
        protocolsSummary.CheckCondition('Sessions Not Started',
                                        StatViewAssistant.EQUAL, 0)
        protocolsSummary.CheckCondition('Sessions Down',
                                        StatViewAssistant.EQUAL, 0)
        ixNetwork.info(protocolsSummary)

        ixNetwork.info('Create Traffic Item')
        trafficItem = ixNetwork.Traffic.TrafficItem.add(Name='BGP Traffic',
                                                        BiDirectional=False,
                                                        TrafficType='ipv4')

        ixNetwork.info('Add endpoint flow group')
        trafficItem.EndpointSet.add(Sources=topology1, Destinations=topology2)

        # Note: A Traffic Item could have multiple EndpointSets (Flow groups).
        #       Therefore, ConfigElement is a list.
        ixNetwork.info('Configuring config elements')
        configElement = trafficItem.ConfigElement.find()[0]
        configElement.FrameRate.Rate = 28
        configElement.FrameRate.Type = 'framesPerSecond'
        configElement.TransmissionControl.FrameCount = 10000
        configElement.TransmissionControl.Type = 'fixedFrameCount'
        configElement.FrameRateDistribution.PortDistribution = 'splitRateEvenly'
        configElement.FrameSize.FixedSize = 128
        trafficItem.Tracking.find()[0].TrackBy = ['flowGroup0']

        trafficItem.Generate()
        ixNetwork.Traffic.Apply()
        ixNetwork.Traffic.Start()

        # StatViewAssistant could also filter by REGEX, LESS_THAN, GREATER_THAN, EQUAL.
        # Examples:
        #    flowStatistics.AddRowFilter('Port Name', StatViewAssistant.REGEX, '^Port 1$')
        #    flowStatistics.AddRowFilter('Tx Frames', StatViewAssistant.LESS_THAN, 50000)

        flowStatistics = StatViewAssistant(ixNetwork, 'Flow Statistics')
        ixNetwork.info('{}\n'.format(flowStatistics))

        for rowNumber, flowStat in enumerate(flowStatistics.Rows):
            ixNetwork.info('\n\nSTATS: {}\n\n'.format(flowStat))
            ixNetwork.info(
                '\nRow:{}  TxPort:{}  RxPort:{}  TxFrames:{}  RxFrames:{}\n'.
                format(rowNumber, flowStat['Tx Port'], flowStat['Rx Port'],
                       flowStat['Tx Frames'], flowStat['Rx Frames']))

        flowStatistics = StatViewAssistant(ixNetwork,
                                           'Traffic Item Statistics')
        ixNetwork.info('{}\n'.format(flowStatistics))

        if module.params['debugMode'] == False:
            # For linux and connection_manager only
            session.remove()

        result['result'] = 'Passed'
        module.exit_json(**result)

    except Exception as errMsg:
        module.fail_json(result='Failed', msg=errMsg)

        if module.params['debugMode'] == False and 'session' in locals():
            session.remove()
コード例 #10
0
    def getStatsPage(self,
                     viewObject=None,
                     viewName='Flow Statistics',
                     csvFile=None,
                     csvEnableFileTimestamp=False,
                     displayStats=True,
                     silentMode=True,
                     ignoreError=False):
        """
        Description
            Get stats by the statistic name or get stats by providing a view object handle.

        Parameters
            csvFile = None or <filename.csv>.
                      None will not create a CSV file.
                      Provide a <filename>.csv to record all stats to a CSV file.
                      Example: getStats(sessionUrl, csvFile='Flow_Statistics.csv')

            csvEnableFileTimestamp = True or False. If True,
                                    timestamp will be appended to the filename.

            displayStats: True or False. True=Display stats.

            ignoreError: True or False.  Returns None if viewName is not found.

            viewObject: The view object:
                        A view object handle could be obtained by calling getViewObject().

            viewName options (Not case sensitive):
               NOTE: Not all statistics are listed here.
                  You could get the statistic viewName directly from the IxNetwork GUI in the
                  statistics.

            'Port Statistics'
            'Tx-Rx Frame Rate Statistics'
            'Port CPU Statistics'
            'Global Protocol Statistics'
            'Protocols Summary'
            'Port Summary'
            'BGP Peer Per Port'
            'OSPFv2-RTR Drill Down'
            'OSPFv2-RTR Per Port'
            'IPv4 Drill Down'
            'L2-L3 Test Summary Statistics'
            'Flow Statistics'
            'Traffic Item Statistics'
            'IGMP Host Drill Down'
            'IGMP Host Per Port'
            'IPv6 Drill Down'
            'MLD Host Drill Down'
            'MLD Host Per Port'
            'PIMv6 IF Drill Down'
            'PIMv6 IF Per Port'
            'Flow View'

         Note: Not all of the viewNames are listed here. You have to get the exact names from
               the IxNetwork GUI in statistics based on your protocol(s).

         Return a dictionary of all the stats: statDict[rowNumber][columnName] == statValue
           Get stats on row 2 for 'Tx Frames' = statDict[2]['Tx Frames']
        """
        rowStats = None
        try:
            TrafficItemStats = StatViewAssistant(self.ixNetwork, viewName)
        except Exception as err:
            self.ixnObj.logInfo("Error in getstats {}".format(err))
            raise Exception('getStats: Failed to get stats values')

        trafficItemStatsDict = {}
        columnCaptions = TrafficItemStats.ColumnHeaders

        if csvFile is not None:
            csvFileName = csvFile.replace(' ', '_')
            if csvEnableFileTimestamp:
                timestamp = datetime.datetime.now().strftime('%H%M%S')
                if '.' in csvFileName:
                    csvFileNameTemp = csvFileName.split('.')[0]
                    csvFileNameExtension = csvFileName.split('.')[1]
                    csvFileName = csvFileNameTemp + '_' + timestamp + '.' + csvFileNameExtension
                else:
                    csvFileName = csvFileName + '_' + timestamp

            csvFile = open(csvFileName, 'w')
            csvWriteObj = csv.writer(csvFile)
            csvWriteObj.writerow(columnCaptions)
            for rowNumber, stat in enumerate(TrafficItemStats.Rows):
                rowStats = stat.RawData
            for row in rowStats:
                csvWriteObj.writerow(row)
            csvFile.close()

        for rowNumber, stat in enumerate(TrafficItemStats.Rows):
            if displayStats:
                self.ixnObj.logInfo('\n Row: {}'.format(rowNumber + 1),
                                    timestamp=False)
            statsDict = {}
            for column in columnCaptions:
                statsDict[column] = stat[column]
                if displayStats:
                    self.ixnObj.logInfo('\t%s: %s' % (column, stat[column]),
                                        timestamp=False)
            trafficItemStatsDict[rowNumber + 1] = statsDict

        return trafficItemStatsDict