Ejemplo n.º 1
0
    def testStreamUnderProject(self):
        """ Build simple config with ports under project object. """
        self.logger.info(StcTestOffline.testBuildConfig.__doc__.strip())

        for port_name in ('Port 1', 'Port 2'):
            self.logger.info('Create Port "%s"', port_name)
            stc_port = StcPort(name=port_name, parent=self.stc.project)

            for sb_name in (port_name + ' StreamBlock 1',
                            port_name + ' StreamBlock 2'):
                self.logger.info('Build StreamBlock "%s"', sb_name)
                stc_sb = StcStream(name=sb_name, parent=stc_port)
                stc_eth = StcObject(objType='ethernet:ethernetii',
                                    parent=stc_sb)
                stc_eth.set_attributes(DstMac='00:10:20:30:40:50')

        test_name = inspect.stack()[0][3]
        self.stc.save_config(
            path.join(path.dirname(__file__), 'configs', test_name + '.tcc'))
Ejemplo n.º 2
0
def test_build_config(logger: logging.Logger, stc: StcApp) -> None:
    """Build simple config from scratch."""
    logger.info(test_build_config.__doc__.strip())

    for port_name in ("Port 1", "Port 2"):
        logger.info('Create Port "%s"', port_name)
        stc_port = StcPort(name=port_name, parent=stc.project)

        for dev_name in (port_name + " Device 1", port_name + " Device 2"):
            logger.info('Build Device "%s"', dev_name)
            stc_dev = StcDevice(name=dev_name, parent=stc_port)
            stc_eth = StcObject(objType="EthIIIf", parent=stc_dev)
            stc_eth.set_attributes(SourceMac="00:11:22:33:44:55")
            stc_dev.set_attributes(TopLevelIf=stc_eth.ref,
                                   PrimaryIf=stc_eth.ref)
            # stc_ip = StcObject(objType="Ipv4If", parent=stc_dev)
            # stc_ip.set_attributes(Address="1.2.3.4", PrefixLength=16)

        for sb_name in (port_name + " StreamBlock 1",
                        port_name + " StreamBlock 2"):
            logger.info('Build StreamBlock "%s"', sb_name)
            stc_sb = StcStream(name=sb_name, parent=stc_port)
            stc_eth = StcObject(objType="ethernet:ethernetii", parent=stc_sb)
            stc_eth.set_attributes(DstMac="00:10:20:30:40:50")

    stc_ports = stc.project.get_children("port")
    assert len(stc_ports) == 2
    for stc_port in stc_ports:
        assert len(stc_port.get_children("generator")) == 1
        assert len(stc_port.get_children("generator", "analyzer")) == 2
        assert len(stc_port.get_children("emulateddevice")) == 2
        assert len(
            stc_port.get_children("emulateddevice", "generator",
                                  "analyzer")) == 4
    for stc_port in stc_ports:
        assert len(stc_port.get_children("streamblock")) == 2

    stc.api.apply()

    test_name = inspect.stack()[0][3]
    stc.save_config(
        Path(__file__).parent.joinpath("configs/temp",
                                       test_name + ".tcc").as_posix())
Ejemplo n.º 3
0
def test_stream_under_project(logger: logging.Logger, stc: StcApp) -> None:
    """Build simple config with ports under project object."""
    logger.info(test_stream_under_project.__doc__.strip())

    for port_name in ("Port 1", "Port 2"):
        logger.info(f'Create Port "{port_name}"')
        stc_port = StcPort(name=port_name, parent=stc.project)

        for sb_name in (port_name + " StreamBlock 1",
                        port_name + " StreamBlock 2"):
            logger.info(f'Build StreamBlock "{sb_name}"')
            stc_sb = StcStream(name=sb_name, parent=stc_port)
            stc_eth = StcObject(objType="ethernet:ethernetii", parent=stc_sb)
            stc_eth.set_attributes(DstMac="00:10:20:30:40:50")

    test_name = inspect.stack()[0][3]
    stc.save_config(
        Path(__file__).parent.joinpath("configs/temp",
                                       test_name + ".tcc").as_posix())
Ejemplo n.º 4
0
    def testBuildConfig(self):
        """ Build simple config from scratch. """
        self.logger.info(StcTestOffline.testBuildConfig.__doc__.strip())

        for port_name in ('Port 1', 'Port 2'):
            self.logger.info('Create Port "%s"', port_name)
            stc_port = StcPort(name=port_name, parent=self.stc.project)

            for dev_name in (port_name + ' Device 1', port_name + ' Device 2'):
                self.logger.info('Build Device "%s"', dev_name)
                stc_dev = StcDevice(name=dev_name, parent=stc_port)
                stc_eth = StcObject(objType='EthIIIf', parent=stc_dev)
                stc_eth.set_attributes(SourceMac='00:11:22:33:44:55')
                stc_ip = StcObject(objType='Ipv4If', parent=stc_dev)
                stc_ip.set_attributes(Address='1.2.3.4', PrefixLength=16)

            for sb_name in (port_name + ' StreamBlock 1',
                            port_name + ' StreamBlock 2'):
                self.logger.info('Build StreamBlock "%s"', sb_name)
                stc_sb = StcStream(name=sb_name, parent=stc_port)
                stc_eth = StcObject(objType='ethernet:ethernetii',
                                    parent=stc_sb)
                stc_eth.set_attributes(DstMac='00:10:20:30:40:50')

        stc_ports = self.stc.project.get_children('port')
        assert (len(stc_ports) == 2)
        for stc_port in stc_ports:
            assert (len(stc_port.get_children('generator')) == 1)
            assert (len(stc_port.get_children('generator', 'analyzer')) == 2)
            assert (len(stc_port.get_children('emulateddevice')) == 2)
            assert (len(
                stc_port.get_children('emulateddevice', 'generator',
                                      'analyzer')) == 4)
        for stc_port in stc_ports:
            assert (len(stc_port.get_children('streamblock')) == 2)

        test_name = inspect.stack()[0][3]
        self.stc.save_config(
            path.join(path.dirname(__file__), 'configs', test_name + '.tcc'))