import six
from yardstick.common import messaging
+from yardstick.common.messaging import payloads
from yardstick.common.messaging import producer
from yardstick.network_services.helpers.samplevnf_helper import PortPairs
This message producer must be instantiated in the process created
"run_traffic" process.
"""
- def __init__(self, pid):
+ def __init__(self, _id):
super(TrafficGeneratorProducer, self).__init__(messaging.TOPIC_TG,
- pid=pid)
+ _id=_id)
+
+ def tg_method_started(self, version=1):
+ """Send a message to inform the traffic generation has started"""
+ self.send_message(
+ messaging.TG_METHOD_STARTED,
+ payloads.TrafficGeneratorPayload(version=version, iteration=0,
+ kpi={}))
+
+ def tg_method_finished(self, version=1):
+ """Send a message to inform the traffic generation has finished"""
+ self.send_message(
+ messaging.TG_METHOD_FINISHED,
+ payloads.TrafficGeneratorPayload(version=version, iteration=0,
+ kpi={}))
+
+ def tg_method_iteration(self, iteration, version=1, kpi=None):
+ """Send a message, with KPI, once an iteration has finished"""
+ kpi = {} if kpi is None else kpi
+ self.send_message(
+ messaging.TG_METHOD_ITERATION,
+ payloads.TrafficGeneratorPayload(version=version,
+ iteration=iteration, kpi=kpi))
@six.add_metaclass(abc.ABCMeta)
"""
pass
- def _setup_mq_producer(self, pid):
+ @staticmethod
+ def _setup_mq_producer(id):
"""Setup the TG MQ producer to send messages between processes
:return: (derived class from ``MessagingProducer``) MQ producer object
"""
- return TrafficGeneratorProducer(pid)
+ return TrafficGeneratorProducer(id)
+
+ def get_mq_producer_id(self):
+ """Return the MQ producer ID if initialized"""
+ if self._mq_producer:
+ return self._mq_producer.get_id()