Merge remote-tracking branch 'origin/topic/dnthayer/ticket1449'

BIT-1449 #merged

* origin/topic/dnthayer/ticket1449:
  Rename broker BIF wrapper functions in a few more places
  Sync the core/leaks/broker/data.bro test with broker/data.bro
  Add missing tests for broker data BIFs
  Code cleanup for some broker tests
  Add script wrapper functions for broker data BIFs
  Add script wrapper functions for broker BIFs
This commit is contained in:
Robin Sommer 2016-04-28 10:24:39 -07:00
commit befad8f825
34 changed files with 1722 additions and 910 deletions

View file

@ -45,7 +45,7 @@ received.
.. btest-include:: ${DOC_ROOT}/frameworks/broker/printing-listener.bro .. btest-include:: ${DOC_ROOT}/frameworks/broker/printing-listener.bro
To send remote print messages, just call :bro:see:`Broker::print`. To send remote print messages, just call :bro:see:`Broker::send_print`.
.. btest-include:: ${DOC_ROOT}/frameworks/broker/printing-connector.bro .. btest-include:: ${DOC_ROOT}/frameworks/broker/printing-connector.bro
@ -75,7 +75,7 @@ new events along with handlers that peers may want to send.
.. btest-include:: ${DOC_ROOT}/frameworks/broker/events-listener.bro .. btest-include:: ${DOC_ROOT}/frameworks/broker/events-listener.bro
There are two different ways to send events. The first is to call the There are two different ways to send events. The first is to call the
:bro:see:`Broker::event` function directly. The second option is to call :bro:see:`Broker::send_event` function directly. The second option is to call
the :bro:see:`Broker::auto_event` function where you specify a the :bro:see:`Broker::auto_event` function where you specify a
particular event that will be automatically sent to peers whenever the particular event that will be automatically sent to peers whenever the
event is called locally via the normal event invocation syntax. event is called locally via the normal event invocation syntax.
@ -144,8 +144,8 @@ If not using the ``auto_publish`` flag, one can use the
functions to manipulate the set of message topics (must match exactly) functions to manipulate the set of message topics (must match exactly)
that are allowed to be sent to peer endpoints. These settings take that are allowed to be sent to peer endpoints. These settings take
precedence over the per-message ``peers`` flag supplied to functions precedence over the per-message ``peers`` flag supplied to functions
that take a :bro:see:`Broker::SendFlags` such as :bro:see:`Broker::print`, that take a :bro:see:`Broker::SendFlags` such as :bro:see:`Broker::send_print`,
:bro:see:`Broker::event`, :bro:see:`Broker::auto_event` or :bro:see:`Broker::send_event`, :bro:see:`Broker::auto_event` or
:bro:see:`Broker::enable_remote_logs`. :bro:see:`Broker::enable_remote_logs`.
If not using the ``auto_advertise`` flag, one can use the If not using the ``auto_advertise`` flag, one can use the

View file

@ -17,11 +17,11 @@ event Broker::outgoing_connection_established(peer_address: string,
{ {
print "Broker::outgoing_connection_established", print "Broker::outgoing_connection_established",
peer_address, peer_port, peer_name; peer_address, peer_port, peer_name;
Broker::event("bro/event/my_event", Broker::event_args(my_event, "hi", 0)); Broker::send_event("bro/event/my_event", Broker::event_args(my_event, "hi", 0));
event my_auto_event("stuff", 88); event my_auto_event("stuff", 88);
Broker::event("bro/event/my_event", Broker::event_args(my_event, "...", 1)); Broker::send_event("bro/event/my_event", Broker::event_args(my_event, "...", 1));
event my_auto_event("more stuff", 51); event my_auto_event("more stuff", 51);
Broker::event("bro/event/my_event", Broker::event_args(my_event, "bye", 2)); Broker::send_event("bro/event/my_event", Broker::event_args(my_event, "bye", 2));
} }
event Broker::outgoing_connection_broken(peer_address: string, event Broker::outgoing_connection_broken(peer_address: string,

View file

@ -14,9 +14,9 @@ event Broker::outgoing_connection_established(peer_address: string,
{ {
print "Broker::outgoing_connection_established", print "Broker::outgoing_connection_established",
peer_address, peer_port, peer_name; peer_address, peer_port, peer_name;
Broker::print("bro/print/hi", "hello"); Broker::send_print("bro/print/hi", "hello");
Broker::print("bro/print/stuff", "..."); Broker::send_print("bro/print/stuff", "...");
Broker::print("bro/print/bye", "goodbye"); Broker::send_print("bro/print/bye", "goodbye");
} }
event Broker::outgoing_connection_broken(peer_address: string, event Broker::outgoing_connection_broken(peer_address: string,

View file

@ -1,5 +1,14 @@
##! Various data structure definitions for use with Bro's communication system. ##! Various data structure definitions for use with Bro's communication system.
module Log;
export {
type Log::ID: enum {
## Dummy place-holder.
UNKNOWN
};
}
module Broker; module Broker;
export { export {
@ -52,4 +61,312 @@ export {
key: Broker::Data; key: Broker::Data;
val: Broker::Data; val: Broker::Data;
}; };
## Enable use of communication.
##
## flags: used to tune the local Broker endpoint behavior.
##
## Returns: true if communication is successfully initialized.
global enable: function(flags: EndpointFlags &default = EndpointFlags()): bool;
## Changes endpoint flags originally supplied to :bro:see:`Broker::enable`.
##
## flags: the new endpoint behavior flags to use.
##
## Returns: true if flags were changed.
global set_endpoint_flags: function(flags: EndpointFlags &default = EndpointFlags()): bool;
## Allow sending messages to peers if associated with the given topic.
## This has no effect if auto publication behavior is enabled via the flags
## supplied to :bro:see:`Broker::enable` or :bro:see:`Broker::set_endpoint_flags`.
##
## topic: a topic to allow messages to be published under.
##
## Returns: true if successful.
global publish_topic: function(topic: string): bool;
## Disallow sending messages to peers if associated with the given topic.
## This has no effect if auto publication behavior is enabled via the flags
## supplied to :bro:see:`Broker::enable` or :bro:see:`Broker::set_endpoint_flags`.
##
## topic: a topic to disallow messages to be published under.
##
## Returns: true if successful.
global unpublish_topic: function(topic: string): bool;
## Listen for remote connections.
##
## p: the TCP port to listen on.
##
## a: an address string on which to accept connections, e.g.
## "127.0.0.1". An empty string refers to @p INADDR_ANY.
##
## reuse: equivalent to behavior of SO_REUSEADDR.
##
## Returns: true if the local endpoint is now listening for connections.
##
## .. bro:see:: Broker::incoming_connection_established
global listen: function(p: port, a: string &default = "", reuse: bool &default = T): bool;
## Initiate a remote connection.
##
## a: an address to connect to, e.g. "localhost" or "127.0.0.1".
##
## p: the TCP port on which the remote side is listening.
##
## retry: an interval at which to retry establishing the
## connection with the remote peer if it cannot be made initially, or
## if it ever becomes disconnected.
##
## Returns: true if it's possible to try connecting with the peer and
## it's a new peer. The actual connection may not be established
## until a later point in time.
##
## .. bro:see:: Broker::outgoing_connection_established
global connect: function(a: string, p: port, retry: interval): bool;
## Remove a remote connection.
##
## a: the address used in previous successful call to :bro:see:`Broker::connect`.
##
## p: the port used in previous successful call to :bro:see:`Broker::connect`.
##
## Returns: true if the arguments match a previously successful call to
## :bro:see:`Broker::connect`.
global disconnect: function(a: string, p: port): bool;
## Print a simple message to any interested peers. The receiver can use
## :bro:see:`Broker::print_handler` to handle messages.
##
## topic: a topic associated with the printed message.
##
## msg: the print message to send to peers.
##
## flags: tune the behavior of how the message is sent.
##
## Returns: true if the message is sent.
global send_print: function(topic: string, msg: string, flags: SendFlags &default = SendFlags()): bool;
## Register interest in all peer print messages that use a certain topic
## prefix. Use :bro:see:`Broker::print_handler` to handle received
## messages.
##
## topic_prefix: a prefix to match against remote message topics.
## e.g. an empty prefix matches everything and "a" matches
## "alice" and "amy" but not "bob".
##
## Returns: true if it's a new print subscription and it is now registered.
global subscribe_to_prints: function(topic_prefix: string): bool;
## Unregister interest in all peer print messages that use a topic prefix.
##
## topic_prefix: a prefix previously supplied to a successful call to
## :bro:see:`Broker::subscribe_to_prints`.
##
## Returns: true if interest in the topic prefix is no longer advertised.
global unsubscribe_to_prints: function(topic_prefix: string): bool;
## Send an event to any interested peers.
##
## topic: a topic associated with the event message.
##
## args: event arguments as made by :bro:see:`Broker::event_args`.
##
## flags: tune the behavior of how the message is sent.
##
## Returns: true if the message is sent.
global send_event: function(topic: string, args: EventArgs, flags: SendFlags &default = SendFlags()): bool;
## Automatically send an event to any interested peers whenever it is
## locally dispatched (e.g. using "event my_event(...);" in a script).
##
## topic: a topic string associated with the event message.
## Peers advertise interest by registering a subscription to some
## prefix of this topic name.
##
## ev: a Bro event value.
##
## flags: tune the behavior of how the message is sent.
##
## Returns: true if automatic event sending is now enabled.
global auto_event: function(topic: string, ev: any, flags: SendFlags &default = SendFlags()): bool;
## Stop automatically sending an event to peers upon local dispatch.
##
## topic: a topic originally given to :bro:see:`Broker::auto_event`.
##
## ev: an event originally given to :bro:see:`Broker::auto_event`.
##
## Returns: true if automatic events will not occur for the topic/event
## pair.
global auto_event_stop: function(topic: string, ev: any): bool;
## Register interest in all peer event messages that use a certain topic
## prefix.
##
## topic_prefix: a prefix to match against remote message topics.
## e.g. an empty prefix matches everything and "a" matches
## "alice" and "amy" but not "bob".
##
## Returns: true if it's a new event subscription and it is now registered.
global subscribe_to_events: function(topic_prefix: string): bool;
## Unregister interest in all peer event messages that use a topic prefix.
##
## topic_prefix: a prefix previously supplied to a successful call to
## :bro:see:`Broker::subscribe_to_events`.
##
## Returns: true if interest in the topic prefix is no longer advertised.
global unsubscribe_to_events: function(topic_prefix: string): bool;
## Enable remote logs for a given log stream.
##
## id: the log stream to enable remote logs for.
##
## flags: tune the behavior of how log entry messages are sent.
##
## Returns: true if remote logs are enabled for the stream.
global enable_remote_logs: function(id: Log::ID, flags: SendFlags &default = SendFlags()): bool;
## Disable remote logs for a given log stream.
##
## id: the log stream to disable remote logs for.
##
## Returns: true if remote logs are disabled for the stream.
global disable_remote_logs: function(id: Log::ID): bool;
## Check if remote logs are enabled for a given log stream.
##
## id: the log stream to check.
##
## Returns: true if remote logs are enabled for the given stream.
global remote_logs_enabled: function(id: Log::ID): bool;
## Register interest in all peer log messages that use a certain topic
## prefix. Logs are implicitly sent with topic "bro/log/<stream-name>" and
## the receiving side processes them through the logging framework as usual.
##
## topic_prefix: a prefix to match against remote message topics.
## e.g. an empty prefix matches everything and "a" matches
## "alice" and "amy" but not "bob".
##
## Returns: true if it's a new log subscription and it is now registered.
global subscribe_to_logs: function(topic_prefix: string): bool;
## Unregister interest in all peer log messages that use a topic prefix.
## Logs are implicitly sent with topic "bro/log/<stream-name>" and the
## receiving side processes them through the logging framework as usual.
##
## topic_prefix: a prefix previously supplied to a successful call to
## :bro:see:`Broker::subscribe_to_logs`.
##
## Returns: true if interest in the topic prefix is no longer advertised.
global unsubscribe_to_logs: function(topic_prefix: string): bool;
} }
@load base/bif/comm.bif
@load base/bif/messaging.bif
module Broker;
function enable(flags: EndpointFlags &default = EndpointFlags()) : bool
{
return __enable(flags);
}
function set_endpoint_flags(flags: EndpointFlags &default = EndpointFlags()): bool
{
return __set_endpoint_flags(flags);
}
function publish_topic(topic: string): bool
{
return __publish_topic(topic);
}
function unpublish_topic(topic: string): bool
{
return __unpublish_topic(topic);
}
function listen(p: port, a: string &default = "", reuse: bool &default = T): bool
{
return __listen(p, a, reuse);
}
function connect(a: string, p: port, retry: interval): bool
{
return __connect(a, p, retry);
}
function disconnect(a: string, p: port): bool
{
return __disconnect(a, p);
}
function send_print(topic: string, msg: string, flags: SendFlags &default = SendFlags()): bool
{
return __send_print(topic, msg, flags);
}
function subscribe_to_prints(topic_prefix: string): bool
{
return __subscribe_to_prints(topic_prefix);
}
function unsubscribe_to_prints(topic_prefix: string): bool
{
return __unsubscribe_to_prints(topic_prefix);
}
function send_event(topic: string, args: EventArgs, flags: SendFlags &default = SendFlags()): bool
{
return __event(topic, args, flags);
}
function auto_event(topic: string, ev: any, flags: SendFlags &default = SendFlags()): bool
{
return __auto_event(topic, ev, flags);
}
function auto_event_stop(topic: string, ev: any): bool
{
return __auto_event_stop(topic, ev);
}
function subscribe_to_events(topic_prefix: string): bool
{
return __subscribe_to_events(topic_prefix);
}
function unsubscribe_to_events(topic_prefix: string): bool
{
return __unsubscribe_to_events(topic_prefix);
}
function enable_remote_logs(id: Log::ID, flags: SendFlags &default = SendFlags()): bool
{
return __enable_remote_logs(id, flags);
}
function disable_remote_logs(id: Log::ID): bool
{
return __disable_remote_logs(id);
}
function remote_logs_enabled(id: Log::ID): bool
{
return __remote_logs_enabled(id);
}
function subscribe_to_logs(topic_prefix: string): bool
{
return __subscribe_to_logs(topic_prefix);
}
function unsubscribe_to_logs(topic_prefix: string): bool
{
return __unsubscribe_to_logs(topic_prefix);
}

File diff suppressed because it is too large Load diff

View file

@ -227,7 +227,7 @@ function acld_add_rule_fun(p: PluginState, r: Rule) : bool
if ( ar$command == "" ) if ( ar$command == "" )
return F; return F;
Broker::event(p$acld_config$acld_topic, Broker::event_args(acld_add_rule, p$acld_id, r, ar)); Broker::send_event(p$acld_config$acld_topic, Broker::event_args(acld_add_rule, p$acld_id, r, ar));
return T; return T;
} }
@ -242,7 +242,7 @@ function acld_remove_rule_fun(p: PluginState, r: Rule) : bool
else else
return F; return F;
Broker::event(p$acld_config$acld_topic, Broker::event_args(acld_remove_rule, p$acld_id, r, ar)); Broker::send_event(p$acld_config$acld_topic, Broker::event_args(acld_remove_rule, p$acld_id, r, ar));
return T; return T;
} }

View file

@ -96,13 +96,13 @@ function broker_name(p: PluginState) : string
function broker_add_rule_fun(p: PluginState, r: Rule) : bool function broker_add_rule_fun(p: PluginState, r: Rule) : bool
{ {
Broker::event(p$broker_topic, Broker::event_args(broker_add_rule, p$broker_id, r)); Broker::send_event(p$broker_topic, Broker::event_args(broker_add_rule, p$broker_id, r));
return T; return T;
} }
function broker_remove_rule_fun(p: PluginState, r: Rule) : bool function broker_remove_rule_fun(p: PluginState, r: Rule) : bool
{ {
Broker::event(p$broker_topic, Broker::event_args(broker_remove_rule, p$broker_id, r)); Broker::send_event(p$broker_topic, Broker::event_args(broker_remove_rule, p$broker_id, r));
return T; return T;
} }

View file

@ -47,14 +47,14 @@ function broker_describe(state: ControllerState): string
function broker_flow_mod_fun(state: ControllerState, match: ofp_match, flow_mod: OpenFlow::ofp_flow_mod): bool function broker_flow_mod_fun(state: ControllerState, match: ofp_match, flow_mod: OpenFlow::ofp_flow_mod): bool
{ {
Broker::event(state$broker_topic, Broker::event_args(broker_flow_mod, state$_name, state$broker_dpid, match, flow_mod)); Broker::send_event(state$broker_topic, Broker::event_args(broker_flow_mod, state$_name, state$broker_dpid, match, flow_mod));
return T; return T;
} }
function broker_flow_clear_fun(state: OpenFlow::ControllerState): bool function broker_flow_clear_fun(state: OpenFlow::ControllerState): bool
{ {
Broker::event(state$broker_topic, Broker::event_args(broker_flow_clear, state$_name, state$broker_dpid)); Broker::send_event(state$broker_topic, Broker::event_args(broker_flow_clear, state$_name, state$broker_dpid));
return T; return T;
} }

View file

@ -9,46 +9,22 @@ module Broker;
type Broker::EndpointFlags: record; type Broker::EndpointFlags: record;
## Enable use of communication. function Broker::__enable%(flags: EndpointFlags%): bool
##
## flags: used to tune the local Broker endpoint behavior.
##
## Returns: true if communication is successfully initialized.
function Broker::enable%(flags: EndpointFlags &default = EndpointFlags()%): bool
%{ %{
return new Val(broker_mgr->Enable(flags), TYPE_BOOL); return new Val(broker_mgr->Enable(flags), TYPE_BOOL);
%} %}
## Changes endpoint flags originally supplied to :bro:see:`Broker::enable`. function Broker::__set_endpoint_flags%(flags: EndpointFlags%): bool
##
## flags: the new endpoint behavior flags to use.
##
## Returns: true if flags were changed.
function Broker::set_endpoint_flags%(flags: EndpointFlags &default = EndpointFlags()%): bool
%{ %{
return new Val(broker_mgr->SetEndpointFlags(flags), TYPE_BOOL); return new Val(broker_mgr->SetEndpointFlags(flags), TYPE_BOOL);
%} %}
## Allow sending messages to peers if associated with the given topic. function Broker::__publish_topic%(topic: string%): bool
## This has no effect if auto publication behavior is enabled via the flags
## supplied to :bro:see:`Broker::enable` or :bro:see:`Broker::set_endpoint_flags`.
##
## topic: a topic to allow messages to be published under.
##
## Returns: true if successful.
function Broker::publish_topic%(topic: string%): bool
%{ %{
return new Val(broker_mgr->PublishTopic(topic->CheckString()), TYPE_BOOL); return new Val(broker_mgr->PublishTopic(topic->CheckString()), TYPE_BOOL);
%} %}
## Disallow sending messages to peers if associated with the given topic. function Broker::__unpublish_topic%(topic: string%): bool
## This has no effect if auto publication behavior is enabled via the flags
## supplied to :bro:see:`Broker::enable` or :bro:see:`Broker::set_endpoint_flags`.
##
## topic: a topic to disallow messages to be published under.
##
## Returns: true if successful.
function Broker::unpublish_topic%(topic: string%): bool
%{ %{
return new Val(broker_mgr->UnpublishTopic(topic->CheckString()), TYPE_BOOL); return new Val(broker_mgr->UnpublishTopic(topic->CheckString()), TYPE_BOOL);
%} %}
@ -124,20 +100,7 @@ event Broker::incoming_connection_established%(peer_name: string%);
## .. bro:see:: Broker::incoming_connection_established ## .. bro:see:: Broker::incoming_connection_established
event Broker::incoming_connection_broken%(peer_name: string%); event Broker::incoming_connection_broken%(peer_name: string%);
## Listen for remote connections. function Broker::__listen%(p: port, a: string, reuse: bool%): bool
##
## p: the TCP port to listen on.
##
## a: an address string on which to accept connections, e.g.
## "127.0.0.1". An empty string refers to @p INADDR_ANY.
##
## reuse: equivalent to behavior of SO_REUSEADDR.
##
## Returns: true if the local endpoint is now listening for connections.
##
## .. bro:see:: Broker::incoming_connection_established
function Broker::listen%(p: port, a: string &default = "",
reuse: bool &default = T%): bool
%{ %{
if ( ! p->IsTCP() ) if ( ! p->IsTCP() )
{ {
@ -150,22 +113,7 @@ function Broker::listen%(p: port, a: string &default = "",
return new Val(rval, TYPE_BOOL); return new Val(rval, TYPE_BOOL);
%} %}
## Initiate a remote connection. function Broker::__connect%(a: string, p: port, retry: interval%): bool
##
## a: an address to connect to, e.g. "localhost" or "127.0.0.1".
##
## p: the TCP port on which the remote side is listening.
##
## retry: an interval at which to retry establishing the
## connection with the remote peer if it cannot be made initially, or
## if it ever becomes disconnected.
##
## Returns: true if it's possible to try connecting with the peer and
## it's a new peer. The actual connection may not be established
## until a later point in time.
##
## .. bro:see:: Broker::outgoing_connection_established
function Broker::connect%(a: string, p: port, retry: interval%): bool
%{ %{
if ( ! p->IsTCP() ) if ( ! p->IsTCP() )
{ {
@ -178,15 +126,7 @@ function Broker::connect%(a: string, p: port, retry: interval%): bool
return new Val(rval, TYPE_BOOL); return new Val(rval, TYPE_BOOL);
%} %}
## Remove a remote connection. function Broker::__disconnect%(a: string, p: port%): bool
##
## a: the address used in previous successful call to :bro:see:`Broker::connect`.
##
## p: the port used in previous successful call to :bro:see:`Broker::connect`.
##
## Returns: true if the arguments match a previously successful call to
## :bro:see:`Broker::connect`.
function Broker::disconnect%(a: string, p: port%): bool
%{ %{
if ( ! p->IsTCP() ) if ( ! p->IsTCP() )
{ {

View file

@ -31,93 +31,44 @@ type Broker::Data: record;
type Broker::TableItem: record; type Broker::TableItem: record;
## Convert any Bro value to communication data. function Broker::__data%(d: any%): Broker::Data
##
## d: any Bro value to attempt to convert (not all types are supported).
##
## Returns: the converted communication data. The returned record's optional
## field will not be set if the conversion was not possible (this can
## happen if the Bro data type does not support being converted to
## communication data).
function Broker::data%(d: any%): Broker::Data
%{ %{
return bro_broker::make_data_val(d); return bro_broker::make_data_val(d);
%} %}
## Retrieve the type of data associated with communication data. function Broker::__data_type%(d: Broker::Data%): Broker::DataType
##
## d: the communication data.
##
## Returns: the data type associated with the communication data.
function Broker::data_type%(d: Broker::Data%): Broker::DataType
%{ %{
return bro_broker::get_data_type(d->AsRecordVal(), frame); return bro_broker::get_data_type(d->AsRecordVal(), frame);
%} %}
## Convert communication data with a type of :bro:see:`Broker::BOOL` to function Broker::__refine_to_bool%(d: Broker::Data%): bool
## an actual Bro value.
##
## d: the communication data to convert.
##
## Returns: the value retrieved from the communication data.
function Broker::refine_to_bool%(d: Broker::Data%): bool
%{ %{
return bro_broker::refine<bool>(d->AsRecordVal(), TYPE_BOOL, frame); return bro_broker::refine<bool>(d->AsRecordVal(), TYPE_BOOL, frame);
%} %}
## Convert communication data with a type of :bro:see:`Broker::INT` to function Broker::__refine_to_int%(d: Broker::Data%): int
## an actual Bro value.
##
## d: the communication data to convert.
##
## Returns: the value retrieved from the communication data.
function Broker::refine_to_int%(d: Broker::Data%): int
%{ %{
return bro_broker::refine<int64_t>(d->AsRecordVal(), TYPE_INT, frame); return bro_broker::refine<int64_t>(d->AsRecordVal(), TYPE_INT, frame);
%} %}
## Convert communication data with a type of :bro:see:`Broker::COUNT` to function Broker::__refine_to_count%(d: Broker::Data%): count
## an actual Bro value.
##
## d: the communication data to convert.
##
## Returns: the value retrieved from the communication data.
function Broker::refine_to_count%(d: Broker::Data%): count
%{ %{
return bro_broker::refine<uint64_t>(d->AsRecordVal(), TYPE_COUNT, frame); return bro_broker::refine<uint64_t>(d->AsRecordVal(), TYPE_COUNT, frame);
%} %}
## Convert communication data with a type of :bro:see:`Broker::DOUBLE` to function Broker::__refine_to_double%(d: Broker::Data%): double
## an actual Bro value.
##
## d: the communication data to convert.
##
## Returns: the value retrieved from the communication data.
function Broker::refine_to_double%(d: Broker::Data%): double
%{ %{
return bro_broker::refine<double>(d->AsRecordVal(), TYPE_DOUBLE, frame); return bro_broker::refine<double>(d->AsRecordVal(), TYPE_DOUBLE, frame);
%} %}
## Convert communication data with a type of :bro:see:`Broker::STRING` to function Broker::__refine_to_string%(d: Broker::Data%): string
## an actual Bro value.
##
## d: the communication data to convert.
##
## Returns: the value retrieved from the communication data.
function Broker::refine_to_string%(d: Broker::Data%): string
%{ %{
return new StringVal(bro_broker::require_data_type<std::string>(d->AsRecordVal(), return new StringVal(bro_broker::require_data_type<std::string>(d->AsRecordVal(),
TYPE_STRING, TYPE_STRING,
frame)); frame));
%} %}
## Convert communication data with a type of :bro:see:`Broker::ADDR` to function Broker::__refine_to_addr%(d: Broker::Data%): addr
## an actual Bro value.
##
## d: the communication data to convert.
##
## Returns: the value retrieved from the communication data.
function Broker::refine_to_addr%(d: Broker::Data%): addr
%{ %{
auto& a = bro_broker::require_data_type<broker::address>(d->AsRecordVal(), auto& a = bro_broker::require_data_type<broker::address>(d->AsRecordVal(),
TYPE_ADDR, frame); TYPE_ADDR, frame);
@ -125,13 +76,7 @@ function Broker::refine_to_addr%(d: Broker::Data%): addr
return new AddrVal(IPAddr(*bits)); return new AddrVal(IPAddr(*bits));
%} %}
## Convert communication data with a type of :bro:see:`Broker::SUBNET` to function Broker::__refine_to_subnet%(d: Broker::Data%): subnet
## an actual Bro value.
##
## d: the communication data to convert.
##
## Returns: the value retrieved from the communication data.
function Broker::refine_to_subnet%(d: Broker::Data%): subnet
%{ %{
auto& a = bro_broker::require_data_type<broker::subnet>(d->AsRecordVal(), auto& a = bro_broker::require_data_type<broker::subnet>(d->AsRecordVal(),
TYPE_SUBNET, frame); TYPE_SUBNET, frame);
@ -139,71 +84,40 @@ function Broker::refine_to_subnet%(d: Broker::Data%): subnet
return new SubNetVal(IPPrefix(IPAddr(*bits), a.length())); return new SubNetVal(IPPrefix(IPAddr(*bits), a.length()));
%} %}
## Convert communication data with a type of :bro:see:`Broker::PORT` to function Broker::__refine_to_port%(d: Broker::Data%): port
## an actual Bro value.
##
## d: the communication data to convert.
##
## Returns: the value retrieved from the communication data.
function Broker::refine_to_port%(d: Broker::Data%): port
%{ %{
auto& a = bro_broker::require_data_type<broker::port>(d->AsRecordVal(), auto& a = bro_broker::require_data_type<broker::port>(d->AsRecordVal(),
TYPE_SUBNET, frame); TYPE_SUBNET, frame);
return new PortVal(a.number(), bro_broker::to_bro_port_proto(a.type())); return new PortVal(a.number(), bro_broker::to_bro_port_proto(a.type()));
%} %}
## Convert communication data with a type of :bro:see:`Broker::TIME` to function Broker::__refine_to_time%(d: Broker::Data%): time
## an actual Bro value.
##
## d: the communication data to convert.
##
## Returns: the value retrieved from the communication data.
function Broker::refine_to_time%(d: Broker::Data%): time
%{ %{
auto v = bro_broker::require_data_type<broker::time_point>(d->AsRecordVal(), auto v = bro_broker::require_data_type<broker::time_point>(d->AsRecordVal(),
TYPE_TIME, frame).value; TYPE_TIME, frame).value;
return new Val(v, TYPE_TIME); return new Val(v, TYPE_TIME);
%} %}
## Convert communication data with a type of :bro:see:`Broker::INTERVAL` to function Broker::__refine_to_interval%(d: Broker::Data%): interval
## an actual Bro value.
##
## d: the communication data to convert.
##
## Returns: the value retrieved from the communication data.
function Broker::refine_to_interval%(d: Broker::Data%): interval
%{ %{
auto v = bro_broker::require_data_type<broker::time_duration>(d->AsRecordVal(), auto v = bro_broker::require_data_type<broker::time_duration>(d->AsRecordVal(),
TYPE_TIME, frame).value; TYPE_TIME, frame).value;
return new Val(v, TYPE_INTERVAL); return new Val(v, TYPE_INTERVAL);
%} %}
## Convert communication data with a type of :bro:see:`Broker::ENUM` to function Broker::__refine_to_enum_name%(d: Broker::Data%): string
## the name of the enum value. :bro:see:`lookup_ID` may be used to convert
## the name to the actual enum value.
##
## d: the communication data to convert.
##
## Returns: the enum name retrieved from the communication data.
function Broker::refine_to_enum_name%(d: Broker::Data%): string
%{ %{
auto& v = bro_broker::require_data_type<broker::enum_value>(d->AsRecordVal(), auto& v = bro_broker::require_data_type<broker::enum_value>(d->AsRecordVal(),
TYPE_ENUM, frame).name; TYPE_ENUM, frame).name;
return new StringVal(v); return new StringVal(v);
%} %}
## Create communication data of type "set". function Broker::__set_create%(%): Broker::Data
function Broker::set_create%(%): Broker::Data
%{ %{
return bro_broker::make_data_val(broker::set()); return bro_broker::make_data_val(broker::set());
%} %}
## Remove all elements within a set. function Broker::__set_clear%(s: Broker::Data%): bool
##
## s: the set to clear.
##
## Returns: always true.
function Broker::set_clear%(s: Broker::Data%): bool
%{ %{
auto& v = bro_broker::require_data_type<broker::set>(s->AsRecordVal(), TYPE_TABLE, auto& v = bro_broker::require_data_type<broker::set>(s->AsRecordVal(), TYPE_TABLE,
frame); frame);
@ -211,26 +125,14 @@ function Broker::set_clear%(s: Broker::Data%): bool
return new Val(true, TYPE_BOOL); return new Val(true, TYPE_BOOL);
%} %}
## Get the number of elements within a set. function Broker::__set_size%(s: Broker::Data%): count
##
## s: the set to query.
##
## Returns: the number of elements in the set.
function Broker::set_size%(s: Broker::Data%): count
%{ %{
auto& v = bro_broker::require_data_type<broker::set>(s->AsRecordVal(), TYPE_TABLE, auto& v = bro_broker::require_data_type<broker::set>(s->AsRecordVal(), TYPE_TABLE,
frame); frame);
return new Val(static_cast<uint64_t>(v.size()), TYPE_COUNT); return new Val(static_cast<uint64_t>(v.size()), TYPE_COUNT);
%} %}
## Check if a set contains a particular element. function Broker::__set_contains%(s: Broker::Data, key: Broker::Data%): bool
##
## s: the set to query.
##
## key: the element to check for existence.
##
## Returns: true if the key exists in the set.
function Broker::set_contains%(s: Broker::Data, key: Broker::Data%): bool
%{ %{
auto& v = bro_broker::require_data_type<broker::set>(s->AsRecordVal(), TYPE_TABLE, auto& v = bro_broker::require_data_type<broker::set>(s->AsRecordVal(), TYPE_TABLE,
frame); frame);
@ -238,14 +140,7 @@ function Broker::set_contains%(s: Broker::Data, key: Broker::Data%): bool
return new Val(v.find(k) != v.end(), TYPE_BOOL); return new Val(v.find(k) != v.end(), TYPE_BOOL);
%} %}
## Insert an element into a set. function Broker::__set_insert%(s: Broker::Data, key: Broker::Data%): bool
##
## s: the set to modify.
##
## key: the element to insert.
##
## Returns: true if the key was inserted, or false if it already existed.
function Broker::set_insert%(s: Broker::Data, key: Broker::Data%): bool
%{ %{
auto& v = bro_broker::require_data_type<broker::set>(s->AsRecordVal(), TYPE_TABLE, auto& v = bro_broker::require_data_type<broker::set>(s->AsRecordVal(), TYPE_TABLE,
frame); frame);
@ -253,14 +148,7 @@ function Broker::set_insert%(s: Broker::Data, key: Broker::Data%): bool
return new Val(v.insert(k).second, TYPE_BOOL); return new Val(v.insert(k).second, TYPE_BOOL);
%} %}
## Remove an element from a set. function Broker::__set_remove%(s: Broker::Data, key: Broker::Data%): bool
##
## s: the set to modify.
##
## key: the element to remove.
##
## Returns: true if the element existed in the set and is now removed.
function Broker::set_remove%(s: Broker::Data, key: Broker::Data%): bool
%{ %{
auto& v = bro_broker::require_data_type<broker::set>(s->AsRecordVal(), TYPE_TABLE, auto& v = bro_broker::require_data_type<broker::set>(s->AsRecordVal(), TYPE_TABLE,
frame); frame);
@ -268,37 +156,18 @@ function Broker::set_remove%(s: Broker::Data, key: Broker::Data%): bool
return new Val(v.erase(k) > 0, TYPE_BOOL); return new Val(v.erase(k) > 0, TYPE_BOOL);
%} %}
## Create an iterator for a set. Note that this makes a copy of the set function Broker::__set_iterator%(s: Broker::Data%): opaque of Broker::SetIterator
## internally to ensure the iterator is always valid.
##
## s: the set to iterate over.
##
## Returns: an iterator.
function Broker::set_iterator%(s: Broker::Data%): opaque of Broker::SetIterator
%{ %{
return new bro_broker::SetIterator(s->AsRecordVal(), TYPE_TABLE, frame); return new bro_broker::SetIterator(s->AsRecordVal(), TYPE_TABLE, frame);
%} %}
## Check if there are no more elements to iterate over. function Broker::__set_iterator_last%(it: opaque of Broker::SetIterator%): bool
##
## it: an iterator.
##
## Returns: true if there are no more elements to iterator over, i.e.
## the iterator is one-past-the-final-element.
function Broker::set_iterator_last%(it: opaque of Broker::SetIterator%): bool
%{ %{
auto set_it = static_cast<bro_broker::SetIterator*>(it); auto set_it = static_cast<bro_broker::SetIterator*>(it);
return new Val(set_it->it == set_it->dat.end(), TYPE_BOOL); return new Val(set_it->it == set_it->dat.end(), TYPE_BOOL);
%} %}
## Advance an iterator. function Broker::__set_iterator_next%(it: opaque of Broker::SetIterator%): bool
##
## it: an iterator.
##
## Returns: true if the iterator, after advancing, still references an element
## in the collection. False if the iterator, after advancing, is
## one-past-the-final-element.
function Broker::set_iterator_next%(it: opaque of Broker::SetIterator%): bool
%{ %{
auto set_it = static_cast<bro_broker::SetIterator*>(it); auto set_it = static_cast<bro_broker::SetIterator*>(it);
@ -309,12 +178,7 @@ function Broker::set_iterator_next%(it: opaque of Broker::SetIterator%): bool
return new Val(set_it->it != set_it->dat.end(), TYPE_BOOL); return new Val(set_it->it != set_it->dat.end(), TYPE_BOOL);
%} %}
## Retrieve the data at an iterator's current position. function Broker::__set_iterator_value%(it: opaque of Broker::SetIterator%): Broker::Data
##
## it: an iterator.
##
## Returns: element in the collection that the iterator currently references.
function Broker::set_iterator_value%(it: opaque of Broker::SetIterator%): Broker::Data
%{ %{
auto set_it = static_cast<bro_broker::SetIterator*>(it); auto set_it = static_cast<bro_broker::SetIterator*>(it);
auto rval = new RecordVal(BifType::Record::Broker::Data); auto rval = new RecordVal(BifType::Record::Broker::Data);
@ -331,18 +195,12 @@ function Broker::set_iterator_value%(it: opaque of Broker::SetIterator%): Broker
return rval; return rval;
%} %}
## Create communication data of type "table". function Broker::__table_create%(%): Broker::Data
function Broker::table_create%(%): Broker::Data
%{ %{
return bro_broker::make_data_val(broker::table()); return bro_broker::make_data_val(broker::table());
%} %}
## Remove all elements within a table. function Broker::__table_clear%(t: Broker::Data%): bool
##
## t: the table to clear.
##
## Returns: always true.
function Broker::table_clear%(t: Broker::Data%): bool
%{ %{
auto& v = bro_broker::require_data_type<broker::table>(t->AsRecordVal(), auto& v = bro_broker::require_data_type<broker::table>(t->AsRecordVal(),
TYPE_TABLE, frame); TYPE_TABLE, frame);
@ -350,26 +208,14 @@ function Broker::table_clear%(t: Broker::Data%): bool
return new Val(true, TYPE_BOOL); return new Val(true, TYPE_BOOL);
%} %}
## Get the number of elements within a table. function Broker::__table_size%(t: Broker::Data%): count
##
## t: the table to query.
##
## Returns: the number of elements in the table.
function Broker::table_size%(t: Broker::Data%): count
%{ %{
auto& v = bro_broker::require_data_type<broker::table>(t->AsRecordVal(), auto& v = bro_broker::require_data_type<broker::table>(t->AsRecordVal(),
TYPE_TABLE, frame); TYPE_TABLE, frame);
return new Val(static_cast<uint64_t>(v.size()), TYPE_COUNT); return new Val(static_cast<uint64_t>(v.size()), TYPE_COUNT);
%} %}
## Check if a table contains a particular key. function Broker::__table_contains%(t: Broker::Data, key: Broker::Data%): bool
##
## t: the table to query.
##
## key: the key to check for existence.
##
## Returns: true if the key exists in the table.
function Broker::table_contains%(t: Broker::Data, key: Broker::Data%): bool
%{ %{
auto& v = bro_broker::require_data_type<broker::table>(t->AsRecordVal(), auto& v = bro_broker::require_data_type<broker::table>(t->AsRecordVal(),
TYPE_TABLE, frame); TYPE_TABLE, frame);
@ -377,17 +223,7 @@ function Broker::table_contains%(t: Broker::Data, key: Broker::Data%): bool
return new Val(v.find(k) != v.end(), TYPE_BOOL); return new Val(v.find(k) != v.end(), TYPE_BOOL);
%} %}
## Insert a key-value pair into a table. function Broker::__table_insert%(t: Broker::Data, key: Broker::Data, val: Broker::Data%): Broker::Data
##
## t: the table to modify.
##
## key: the key at which to insert the value.
##
## val: the value to insert.
##
## Returns: true if the key-value pair was inserted, or false if the key
## already existed in the table.
function Broker::table_insert%(t: Broker::Data, key: Broker::Data, val: Broker::Data%): Broker::Data
%{ %{
auto& table = bro_broker::require_data_type<broker::table>(t->AsRecordVal(), auto& table = bro_broker::require_data_type<broker::table>(t->AsRecordVal(),
TYPE_TABLE, frame); TYPE_TABLE, frame);
@ -408,15 +244,7 @@ function Broker::table_insert%(t: Broker::Data, key: Broker::Data, val: Broker::
} }
%} %}
## Remove a key-value pair from a table. function Broker::__table_remove%(t: Broker::Data, key: Broker::Data%): Broker::Data
##
## t: the table to modify.
##
## key: the key to remove from the table.
##
## Returns: the value associated with the key. If the key did not exist, then
## the optional field of the returned record is not set.
function Broker::table_remove%(t: Broker::Data, key: Broker::Data%): Broker::Data
%{ %{
auto& table = bro_broker::require_data_type<broker::table>(t->AsRecordVal(), auto& table = bro_broker::require_data_type<broker::table>(t->AsRecordVal(),
TYPE_TABLE, frame); TYPE_TABLE, frame);
@ -433,15 +261,7 @@ function Broker::table_remove%(t: Broker::Data, key: Broker::Data%): Broker::Dat
} }
%} %}
## Retrieve a value from a table. function Broker::__table_lookup%(t: Broker::Data, key: Broker::Data%): Broker::Data
##
## t: the table to query.
##
## key: the key to lookup.
##
## Returns: the value associated with the key. If the key did not exist, then
## the optional field of the returned record is not set.
function Broker::table_lookup%(t: Broker::Data, key: Broker::Data%): Broker::Data
%{ %{
auto& table = bro_broker::require_data_type<broker::table>(t->AsRecordVal(), auto& table = bro_broker::require_data_type<broker::table>(t->AsRecordVal(),
TYPE_TABLE, frame); TYPE_TABLE, frame);
@ -454,37 +274,18 @@ function Broker::table_lookup%(t: Broker::Data, key: Broker::Data%): Broker::Dat
return bro_broker::make_data_val(it->second); return bro_broker::make_data_val(it->second);
%} %}
## Create an iterator for a table. Note that this makes a copy of the table function Broker::__table_iterator%(t: Broker::Data%): opaque of Broker::TableIterator
## internally to ensure the iterator is always valid.
##
## t: the table to iterate over.
##
## Returns: an iterator.
function Broker::table_iterator%(t: Broker::Data%): opaque of Broker::TableIterator
%{ %{
return new bro_broker::TableIterator(t->AsRecordVal(), TYPE_TABLE, frame); return new bro_broker::TableIterator(t->AsRecordVal(), TYPE_TABLE, frame);
%} %}
## Check if there are no more elements to iterate over. function Broker::__table_iterator_last%(it: opaque of Broker::TableIterator%): bool
##
## it: an iterator.
##
## Returns: true if there are no more elements to iterator over, i.e.
## the iterator is one-past-the-final-element.
function Broker::table_iterator_last%(it: opaque of Broker::TableIterator%): bool
%{ %{
auto ti = static_cast<bro_broker::TableIterator*>(it); auto ti = static_cast<bro_broker::TableIterator*>(it);
return new Val(ti->it == ti->dat.end(), TYPE_BOOL); return new Val(ti->it == ti->dat.end(), TYPE_BOOL);
%} %}
## Advance an iterator. function Broker::__table_iterator_next%(it: opaque of Broker::TableIterator%): bool
##
## it: an iterator.
##
## Returns: true if the iterator, after advancing, still references an element
## in the collection. False if the iterator, after advancing, is
## one-past-the-final-element.
function Broker::table_iterator_next%(it: opaque of Broker::TableIterator%): bool
%{ %{
auto ti = static_cast<bro_broker::TableIterator*>(it); auto ti = static_cast<bro_broker::TableIterator*>(it);
@ -495,12 +296,7 @@ function Broker::table_iterator_next%(it: opaque of Broker::TableIterator%): boo
return new Val(ti->it != ti->dat.end(), TYPE_BOOL); return new Val(ti->it != ti->dat.end(), TYPE_BOOL);
%} %}
## Retrieve the data at an iterator's current position. function Broker::__table_iterator_value%(it: opaque of Broker::TableIterator%): Broker::TableItem
##
## it: an iterator.
##
## Returns: element in the collection that the iterator currently references.
function Broker::table_iterator_value%(it: opaque of Broker::TableIterator%): Broker::TableItem
%{ %{
auto ti = static_cast<bro_broker::TableIterator*>(it); auto ti = static_cast<bro_broker::TableIterator*>(it);
auto rval = new RecordVal(BifType::Record::Broker::TableItem); auto rval = new RecordVal(BifType::Record::Broker::TableItem);
@ -522,18 +318,12 @@ function Broker::table_iterator_value%(it: opaque of Broker::TableIterator%): Br
return rval; return rval;
%} %}
## Create communication data of type "vector". function Broker::__vector_create%(%): Broker::Data
function Broker::vector_create%(%): Broker::Data
%{ %{
return bro_broker::make_data_val(broker::vector()); return bro_broker::make_data_val(broker::vector());
%} %}
## Remove all elements within a vector. function Broker::__vector_clear%(v: Broker::Data%): bool
##
## v: the vector to clear.
##
## Returns: always true.
function Broker::vector_clear%(v: Broker::Data%): bool
%{ %{
auto& vec = bro_broker::require_data_type<broker::vector>(v->AsRecordVal(), auto& vec = bro_broker::require_data_type<broker::vector>(v->AsRecordVal(),
TYPE_VECTOR, frame); TYPE_VECTOR, frame);
@ -541,30 +331,14 @@ function Broker::vector_clear%(v: Broker::Data%): bool
return new Val(true, TYPE_BOOL); return new Val(true, TYPE_BOOL);
%} %}
## Get the number of elements within a vector. function Broker::__vector_size%(v: Broker::Data%): count
##
## v: the vector to query.
##
## Returns: the number of elements in the vector.
function Broker::vector_size%(v: Broker::Data%): count
%{ %{
auto& vec = bro_broker::require_data_type<broker::vector>(v->AsRecordVal(), auto& vec = bro_broker::require_data_type<broker::vector>(v->AsRecordVal(),
TYPE_VECTOR, frame); TYPE_VECTOR, frame);
return new Val(static_cast<uint64_t>(vec.size()), TYPE_COUNT); return new Val(static_cast<uint64_t>(vec.size()), TYPE_COUNT);
%} %}
## Insert an element into a vector at a particular position, possibly displacing function Broker::__vector_insert%(v: Broker::Data, d: Broker::Data, idx: count%): bool
## existing elements (insertion always grows the size of the vector by one).
##
## v: the vector to modify.
##
## d: the element to insert.
##
## idx: the index at which to insert the data. If it is greater than the
## current size of the vector, the element is inserted at the end.
##
## Returns: always true.
function Broker::vector_insert%(v: Broker::Data, d: Broker::Data, idx: count%): bool
%{ %{
auto& vec = bro_broker::require_data_type<broker::vector>(v->AsRecordVal(), auto& vec = bro_broker::require_data_type<broker::vector>(v->AsRecordVal(),
TYPE_VECTOR, frame); TYPE_VECTOR, frame);
@ -574,17 +348,7 @@ function Broker::vector_insert%(v: Broker::Data, d: Broker::Data, idx: count%):
return new Val(true, TYPE_BOOL); return new Val(true, TYPE_BOOL);
%} %}
## Replace an element in a vector at a particular position. function Broker::__vector_replace%(v: Broker::Data, d: Broker::Data, idx: count%): Broker::Data
##
## v: the vector to modify.
##
## d: the element to insert.
##
## idx: the index to replace.
##
## Returns: the value that was just evicted. If the index was larger than any
## valid index, the optional field of the returned record is not set.
function Broker::vector_replace%(v: Broker::Data, d: Broker::Data, idx: count%): Broker::Data
%{ %{
auto& vec = bro_broker::require_data_type<broker::vector>(v->AsRecordVal(), auto& vec = bro_broker::require_data_type<broker::vector>(v->AsRecordVal(),
TYPE_VECTOR, frame); TYPE_VECTOR, frame);
@ -598,15 +362,7 @@ function Broker::vector_replace%(v: Broker::Data, d: Broker::Data, idx: count%):
return rval; return rval;
%} %}
## Remove an element from a vector at a particular position. function Broker::__vector_remove%(v: Broker::Data, idx: count%): Broker::Data
##
## v: the vector to modify.
##
## idx: the index to remove.
##
## Returns: the value that was just evicted. If the index was larger than any
## valid index, the optional field of the returned record is not set.
function Broker::vector_remove%(v: Broker::Data, idx: count%): Broker::Data
%{ %{
auto& vec = bro_broker::require_data_type<broker::vector>(v->AsRecordVal(), auto& vec = bro_broker::require_data_type<broker::vector>(v->AsRecordVal(),
TYPE_VECTOR, frame); TYPE_VECTOR, frame);
@ -619,15 +375,7 @@ function Broker::vector_remove%(v: Broker::Data, idx: count%): Broker::Data
return rval; return rval;
%} %}
## Lookup an element in a vector at a particular position. function Broker::__vector_lookup%(v: Broker::Data, idx: count%): Broker::Data
##
## v: the vector to query.
##
## idx: the index to lookup.
##
## Returns: the value at the index. If the index was larger than any
## valid index, the optional field of the returned record is not set.
function Broker::vector_lookup%(v: Broker::Data, idx: count%): Broker::Data
%{ %{
auto& vec = bro_broker::require_data_type<broker::vector>(v->AsRecordVal(), auto& vec = bro_broker::require_data_type<broker::vector>(v->AsRecordVal(),
TYPE_VECTOR, frame); TYPE_VECTOR, frame);
@ -638,37 +386,18 @@ function Broker::vector_lookup%(v: Broker::Data, idx: count%): Broker::Data
return bro_broker::make_data_val(vec[idx]); return bro_broker::make_data_val(vec[idx]);
%} %}
## Create an iterator for a vector. Note that this makes a copy of the vector function Broker::__vector_iterator%(v: Broker::Data%): opaque of Broker::VectorIterator
## internally to ensure the iterator is always valid.
##
## v: the vector to iterate over.
##
## Returns: an iterator.
function Broker::vector_iterator%(v: Broker::Data%): opaque of Broker::VectorIterator
%{ %{
return new bro_broker::VectorIterator(v->AsRecordVal(), TYPE_VECTOR, frame); return new bro_broker::VectorIterator(v->AsRecordVal(), TYPE_VECTOR, frame);
%} %}
## Check if there are no more elements to iterate over. function Broker::__vector_iterator_last%(it: opaque of Broker::VectorIterator%): bool
##
## it: an iterator.
##
## Returns: true if there are no more elements to iterator over, i.e.
## the iterator is one-past-the-final-element.
function Broker::vector_iterator_last%(it: opaque of Broker::VectorIterator%): bool
%{ %{
auto vi = static_cast<bro_broker::VectorIterator*>(it); auto vi = static_cast<bro_broker::VectorIterator*>(it);
return new Val(vi->it == vi->dat.end(), TYPE_BOOL); return new Val(vi->it == vi->dat.end(), TYPE_BOOL);
%} %}
## Advance an iterator. function Broker::__vector_iterator_next%(it: opaque of Broker::VectorIterator%): bool
##
## it: an iterator.
##
## Returns: true if the iterator, after advancing, still references an element
## in the collection. False if the iterator, after advancing, is
## one-past-the-final-element.
function Broker::vector_iterator_next%(it: opaque of Broker::VectorIterator%): bool
%{ %{
auto vi = static_cast<bro_broker::VectorIterator*>(it); auto vi = static_cast<bro_broker::VectorIterator*>(it);
@ -679,12 +408,7 @@ function Broker::vector_iterator_next%(it: opaque of Broker::VectorIterator%): b
return new Val(vi->it != vi->dat.end(), TYPE_BOOL); return new Val(vi->it != vi->dat.end(), TYPE_BOOL);
%} %}
## Retrieve the data at an iterator's current position. function Broker::__vector_iterator_value%(it: opaque of Broker::VectorIterator%): Broker::Data
##
## it: an iterator.
##
## Returns: element in the collection that the iterator currently references.
function Broker::vector_iterator_value%(it: opaque of Broker::VectorIterator%): Broker::Data
%{ %{
auto vi = static_cast<bro_broker::VectorIterator*>(it); auto vi = static_cast<bro_broker::VectorIterator*>(it);
auto rval = new RecordVal(BifType::Record::Broker::Data); auto rval = new RecordVal(BifType::Record::Broker::Data);
@ -701,38 +425,19 @@ function Broker::vector_iterator_value%(it: opaque of Broker::VectorIterator%):
return rval; return rval;
%} %}
## Create communication data of type "record". function Broker::__record_create%(sz: count%): Broker::Data
##
## sz: the number of fields in the record.
##
## Returns: record data, with all fields uninitialized.
function Broker::record_create%(sz: count%): Broker::Data
%{ %{
return bro_broker::make_data_val(broker::record(std::vector<broker::record::field>(sz))); return bro_broker::make_data_val(broker::record(std::vector<broker::record::field>(sz)));
%} %}
## Get the number of fields within a record. function Broker::__record_size%(r: Broker::Data%): count
##
## r: the record to query.
##
## Returns: the number of fields in the record.
function Broker::record_size%(r: Broker::Data%): count
%{ %{
auto& v = bro_broker::require_data_type<broker::record>(r->AsRecordVal(), auto& v = bro_broker::require_data_type<broker::record>(r->AsRecordVal(),
TYPE_RECORD, frame); TYPE_RECORD, frame);
return new Val(static_cast<uint64_t>(v.fields.size()), TYPE_COUNT); return new Val(static_cast<uint64_t>(v.fields.size()), TYPE_COUNT);
%} %}
## Replace a field in a record at a particular position. function Broker::__record_assign%(r: Broker::Data, d: Broker::Data, idx: count%): bool
##
## r: the record to modify.
##
## d: the new field value to assign.
##
## idx: the index to replace.
##
## Returns: false if the index was larger than any valid index, else true.
function Broker::record_assign%(r: Broker::Data, d: Broker::Data, idx: count%): bool
%{ %{
auto& v = bro_broker::require_data_type<broker::record>(r->AsRecordVal(), auto& v = bro_broker::require_data_type<broker::record>(r->AsRecordVal(),
TYPE_RECORD, frame); TYPE_RECORD, frame);
@ -745,16 +450,7 @@ function Broker::record_assign%(r: Broker::Data, d: Broker::Data, idx: count%):
return new Val(true, TYPE_BOOL); return new Val(true, TYPE_BOOL);
%} %}
## Lookup a field in a record at a particular position. function Broker::__record_lookup%(r: Broker::Data, idx: count%): Broker::Data
##
## r: the record to query.
##
## idx: the index to lookup.
##
## Returns: the value at the index. The optional field of the returned record
## may not be set if the field of the record has no value or if the
## index was not valid.
function Broker::record_lookup%(r: Broker::Data, idx: count%): Broker::Data
%{ %{
auto& v = bro_broker::require_data_type<broker::record>(r->AsRecordVal(), auto& v = bro_broker::require_data_type<broker::record>(r->AsRecordVal(),
TYPE_RECORD, frame); TYPE_RECORD, frame);
@ -768,37 +464,18 @@ function Broker::record_lookup%(r: Broker::Data, idx: count%): Broker::Data
return bro_broker::make_data_val(*v.fields[idx]); return bro_broker::make_data_val(*v.fields[idx]);
%} %}
## Create an iterator for a record. Note that this makes a copy of the record function Broker::__record_iterator%(r: Broker::Data%): opaque of Broker::RecordIterator
## internally to ensure the iterator is always valid.
##
## r: the record to iterate over.
##
## Returns: an iterator.
function Broker::record_iterator%(r: Broker::Data%): opaque of Broker::RecordIterator
%{ %{
return new bro_broker::RecordIterator(r->AsRecordVal(), TYPE_RECORD, frame); return new bro_broker::RecordIterator(r->AsRecordVal(), TYPE_RECORD, frame);
%} %}
## Check if there are no more elements to iterate over. function Broker::__record_iterator_last%(it: opaque of Broker::RecordIterator%): bool
##
## it: an iterator.
##
## Returns: true if there are no more elements to iterator over, i.e.
## the iterator is one-past-the-final-element.
function Broker::record_iterator_last%(it: opaque of Broker::RecordIterator%): bool
%{ %{
auto ri = static_cast<bro_broker::RecordIterator*>(it); auto ri = static_cast<bro_broker::RecordIterator*>(it);
return new Val(ri->it == ri->dat.fields.end(), TYPE_BOOL); return new Val(ri->it == ri->dat.fields.end(), TYPE_BOOL);
%} %}
## Advance an iterator. function Broker::__record_iterator_next%(it: opaque of Broker::RecordIterator%): bool
##
## it: an iterator.
##
## Returns: true if the iterator, after advancing, still references an element
## in the collection. False if the iterator, after advancing, is
## one-past-the-final-element.
function Broker::record_iterator_next%(it: opaque of Broker::RecordIterator%): bool
%{ %{
auto ri = static_cast<bro_broker::RecordIterator*>(it); auto ri = static_cast<bro_broker::RecordIterator*>(it);
@ -809,12 +486,7 @@ function Broker::record_iterator_next%(it: opaque of Broker::RecordIterator%): b
return new Val(ri->it != ri->dat.fields.end(), TYPE_BOOL); return new Val(ri->it != ri->dat.fields.end(), TYPE_BOOL);
%} %}
## Retrieve the data at an iterator's current position. function Broker::__record_iterator_value%(it: opaque of Broker::RecordIterator%): Broker::Data
##
## it: an iterator.
##
## Returns: element in the collection that the iterator currently references.
function Broker::record_iterator_value%(it: opaque of Broker::RecordIterator%): Broker::Data
%{ %{
auto ri = static_cast<bro_broker::RecordIterator*>(it); auto ri = static_cast<bro_broker::RecordIterator*>(it);
auto rval = new RecordVal(BifType::Record::Broker::Data); auto rval = new RecordVal(BifType::Record::Broker::Data);

View file

@ -13,202 +13,99 @@ type Broker::SendFlags: record;
type Broker::EventArgs: record; type Broker::EventArgs: record;
## Used to handle remote print messages from peers that call ## Used to handle remote print messages from peers that call
## :bro:see:`Broker::print`. ## :bro:see:`Broker::send_print`.
event Broker::print_handler%(msg: string%); event Broker::print_handler%(msg: string%);
## Print a simple message to any interested peers. The receiver can use function Broker::__send_print%(topic: string, msg: string, flags: Broker::SendFlags%): bool
## :bro:see:`Broker::print_handler` to handle messages.
##
## topic: a topic associated with the printed message.
##
## msg: the print message to send to peers.
##
## flags: tune the behavior of how the message is sent.
##
## Returns: true if the message is sent.
function Broker::print%(topic: string, msg: string,
flags: SendFlags &default = SendFlags()%): bool
%{ %{
auto rval = broker_mgr->Print(topic->CheckString(), msg->CheckString(), auto rval = broker_mgr->Print(topic->CheckString(), msg->CheckString(),
flags); flags);
return new Val(rval, TYPE_BOOL); return new Val(rval, TYPE_BOOL);
%} %}
## Register interest in all peer print messages that use a certain topic prefix. function Broker::__subscribe_to_prints%(topic_prefix: string%): bool
## Use :bro:see:`Broker::print_handler` to handle received messages.
##
## topic_prefix: a prefix to match against remote message topics.
## e.g. an empty prefix matches everything and "a" matches
## "alice" and "amy" but not "bob".
##
## Returns: true if it's a new print subscription and it is now registered.
function Broker::subscribe_to_prints%(topic_prefix: string%): bool
%{ %{
auto rval = broker_mgr->SubscribeToPrints(topic_prefix->CheckString()); auto rval = broker_mgr->SubscribeToPrints(topic_prefix->CheckString());
return new Val(rval, TYPE_BOOL); return new Val(rval, TYPE_BOOL);
%} %}
## Unregister interest in all peer print messages that use a topic prefix. function Broker::__unsubscribe_to_prints%(topic_prefix: string%): bool
##
## topic_prefix: a prefix previously supplied to a successful call to
## :bro:see:`Broker::subscribe_to_prints`.
##
## Returns: true if interest in the topic prefix is no longer advertised.
function Broker::unsubscribe_to_prints%(topic_prefix: string%): bool
%{ %{
auto rval = broker_mgr->UnsubscribeToPrints(topic_prefix->CheckString()); auto rval = broker_mgr->UnsubscribeToPrints(topic_prefix->CheckString());
return new Val(rval, TYPE_BOOL); return new Val(rval, TYPE_BOOL);
%} %}
## Create a data structure that may be used to send a remote event via ## Create a data structure that may be used to send a remote event via
## :bro:see:`Broker::event`. ## :bro:see:`Broker::send_event`.
## ##
## args: an event, followed by a list of argument values that may be used ## args: an event, followed by a list of argument values that may be used
## to call it. ## to call it.
## ##
## Returns: opaque communication data that may be used to send a remote event. ## Returns: opaque communication data that may be used to send a remote
## event.
function Broker::event_args%(...%): Broker::EventArgs function Broker::event_args%(...%): Broker::EventArgs
%{ %{
auto rval = broker_mgr->MakeEventArgs(@ARGS@); auto rval = broker_mgr->MakeEventArgs(@ARGS@);
return rval; return rval;
%} %}
## Send an event to any interested peers. function Broker::__event%(topic: string, args: Broker::EventArgs, flags: Broker::SendFlags%): bool
##
## topic: a topic associated with the event message.
##
## args: event arguments as made by :bro:see:`Broker::event_args`.
##
## flags: tune the behavior of how the message is sent.
##
## Returns: true if the message is sent.
function Broker::event%(topic: string, args: Broker::EventArgs,
flags: SendFlags &default = SendFlags()%): bool
%{ %{
auto rval = broker_mgr->Event(topic->CheckString(), args->AsRecordVal(), auto rval = broker_mgr->Event(topic->CheckString(), args->AsRecordVal(),
flags); flags);
return new Val(rval, TYPE_BOOL); return new Val(rval, TYPE_BOOL);
%} %}
## Automatically send an event to any interested peers whenever it is function Broker::__auto_event%(topic: string, ev: any, flags: Broker::SendFlags%): bool
## locally dispatched (e.g. using "event my_event(...);" in a script).
##
## topic: a topic string associated with the event message.
## Peers advertise interest by registering a subscription to some prefix
## of this topic name.
##
## ev: a Bro event value.
##
## flags: tune the behavior of how the message is sent.
##
## Returns: true if automatic event sending is now enabled.
function Broker::auto_event%(topic: string, ev: any,
flags: SendFlags &default = SendFlags()%): bool
%{ %{
auto rval = broker_mgr->AutoEvent(topic->CheckString(), ev, flags); auto rval = broker_mgr->AutoEvent(topic->CheckString(), ev, flags);
return new Val(rval, TYPE_BOOL); return new Val(rval, TYPE_BOOL);
%} %}
## Stop automatically sending an event to peers upon local dispatch. function Broker::__auto_event_stop%(topic: string, ev: any%): bool
##
## topic: a topic originally given to :bro:see:`Broker::auto_event`.
##
## ev: an event originally given to :bro:see:`Broker::auto_event`.
##
## Returns: true if automatic events will not occur for the topic/event pair.
function Broker::auto_event_stop%(topic: string, ev: any%): bool
%{ %{
auto rval = broker_mgr->AutoEventStop(topic->CheckString(), ev); auto rval = broker_mgr->AutoEventStop(topic->CheckString(), ev);
return new Val(rval, TYPE_BOOL); return new Val(rval, TYPE_BOOL);
%} %}
## Register interest in all peer event messages that use a certain topic prefix. function Broker::__subscribe_to_events%(topic_prefix: string%): bool
##
## topic_prefix: a prefix to match against remote message topics.
## e.g. an empty prefix matches everything and "a" matches
## "alice" and "amy" but not "bob".
##
## Returns: true if it's a new event subscription and it is now registered.
function Broker::subscribe_to_events%(topic_prefix: string%): bool
%{ %{
auto rval = broker_mgr->SubscribeToEvents(topic_prefix->CheckString()); auto rval = broker_mgr->SubscribeToEvents(topic_prefix->CheckString());
return new Val(rval, TYPE_BOOL); return new Val(rval, TYPE_BOOL);
%} %}
## Unregister interest in all peer event messages that use a topic prefix. function Broker::__unsubscribe_to_events%(topic_prefix: string%): bool
##
## topic_prefix: a prefix previously supplied to a successful call to
## :bro:see:`Broker::subscribe_to_events`.
##
## Returns: true if interest in the topic prefix is no longer advertised.
function Broker::unsubscribe_to_events%(topic_prefix: string%): bool
%{ %{
auto rval = broker_mgr->UnsubscribeToEvents(topic_prefix->CheckString()); auto rval = broker_mgr->UnsubscribeToEvents(topic_prefix->CheckString());
return new Val(rval, TYPE_BOOL); return new Val(rval, TYPE_BOOL);
%} %}
## Enable remote logs for a given log stream. function Broker::__enable_remote_logs%(id: Log::ID, flags: Broker::SendFlags%): bool
##
## id: the log stream to enable remote logs for.
##
## flags: tune the behavior of how log entry messages are sent.
##
## Returns: true if remote logs are enabled for the stream.
function
Broker::enable_remote_logs%(id: Log::ID,
flags: SendFlags &default = SendFlags()%): bool
%{ %{
auto rval = log_mgr->EnableRemoteLogs(id->AsEnumVal(), auto rval = log_mgr->EnableRemoteLogs(id->AsEnumVal(),
bro_broker::Manager::send_flags_to_int(flags)); bro_broker::Manager::send_flags_to_int(flags));
return new Val(rval, TYPE_BOOL); return new Val(rval, TYPE_BOOL);
%} %}
## Disable remote logs for a given log stream. function Broker::__disable_remote_logs%(id: Log::ID%): bool
##
## id: the log stream to disable remote logs for.
##
## Returns: true if remote logs are disabled for the stream.
function Broker::disable_remote_logs%(id: Log::ID%): bool
%{ %{
auto rval = log_mgr->DisableRemoteLogs(id->AsEnumVal()); auto rval = log_mgr->DisableRemoteLogs(id->AsEnumVal());
return new Val(rval, TYPE_BOOL); return new Val(rval, TYPE_BOOL);
%} %}
## Check if remote logs are enabled for a given log stream. function Broker::__remote_logs_enabled%(id: Log::ID%): bool
##
## id: the log stream to check.
##
## Returns: true if remote logs are enabled for the given stream.
function Broker::remote_logs_enabled%(id: Log::ID%): bool
%{ %{
auto rval = log_mgr->RemoteLogsAreEnabled(id->AsEnumVal()); auto rval = log_mgr->RemoteLogsAreEnabled(id->AsEnumVal());
return new Val(rval, TYPE_BOOL); return new Val(rval, TYPE_BOOL);
%} %}
## Register interest in all peer log messages that use a certain topic prefix. function Broker::__subscribe_to_logs%(topic_prefix: string%): bool
## Logs are implicitly sent with topic "bro/log/<stream-name>" and the
## receiving side processes them through the logging framework as usual.
##
## topic_prefix: a prefix to match against remote message topics.
## e.g. an empty prefix matches everything and "a" matches
## "alice" and "amy" but not "bob".
##
## Returns: true if it's a new log subscription and it is now registered.
function Broker::subscribe_to_logs%(topic_prefix: string%): bool
%{ %{
auto rval = broker_mgr->SubscribeToLogs(topic_prefix->CheckString()); auto rval = broker_mgr->SubscribeToLogs(topic_prefix->CheckString());
return new Val(rval, TYPE_BOOL); return new Val(rval, TYPE_BOOL);
%} %}
## Unregister interest in all peer log messages that use a topic prefix. function Broker::__unsubscribe_to_logs%(topic_prefix: string%): bool
## Logs are implicitly sent with topic "bro/log/<stream-name>" and the
## receiving side processes them through the logging framework as usual.
##
## topic_prefix: a prefix previously supplied to a successful call to
## :bro:see:`Broker::subscribe_to_logs`.
##
## Returns: true if interest in the topic prefix is no longer advertised.
function Broker::unsubscribe_to_logs%(topic_prefix: string%): bool
%{ %{
auto rval = broker_mgr->UnsubscribeToLogs(topic_prefix->CheckString()); auto rval = broker_mgr->UnsubscribeToLogs(topic_prefix->CheckString());
return new Val(rval, TYPE_BOOL); return new Val(rval, TYPE_BOOL);

View file

@ -23,16 +23,7 @@ enum BackendType %{
ROCKSDB, ROCKSDB,
%} %}
## Create a master data store which contains key-value pairs. function Broker::__create_master%(id: string, b: BackendType,
##
## id: a unique name for the data store.
##
## b: the storage backend to use.
##
## options: tunes how some storage backends operate.
##
## Returns: a handle to the data store.
function Broker::create_master%(id: string, b: BackendType &default = MEMORY,
options: BackendOptions &default = BackendOptions()%): opaque of Broker::Handle options: BackendOptions &default = BackendOptions()%): opaque of Broker::Handle
%{ %{
auto id_str = id->CheckString(); auto id_str = id->CheckString();
@ -53,29 +44,7 @@ function Broker::create_master%(id: string, b: BackendType &default = MEMORY,
return rval; return rval;
%} %}
## Create a clone of a master data store which may live with a remote peer. function Broker::__create_clone%(id: string, b: BackendType,
## A clone automatically synchronizes to the master by automatically receiving
## modifications and applying them locally. Direct modifications are not
## possible, they must be sent through the master store, which then
## automatically broadcasts the changes out to clones. But queries may be made
## directly against the local cloned copy, which may be resolved quicker than
## reaching out to a remote master store.
##
## id: the unique name which identifies the master data store.
##
## b: the storage backend to use.
##
## options: tunes how some storage backends operate.
##
## resync: the interval at which to re-attempt synchronizing with the master
## store should the connection be lost. If the clone has not yet
## synchronized for the first time, updates and queries queue up until
## the synchronization completes. After, if the connection to the
## master store is lost, queries continue to use the clone's version,
## but updates will be lost until the master is once again available.
##
## Returns: a handle to the data store.
function Broker::create_clone%(id: string, b: BackendType &default = MEMORY,
options: BackendOptions &default = BackendOptions(), options: BackendOptions &default = BackendOptions(),
resync: interval &default = 1sec%): opaque of Broker::Handle resync: interval &default = 1sec%): opaque of Broker::Handle
%{ %{
@ -98,13 +67,7 @@ function Broker::create_clone%(id: string, b: BackendType &default = MEMORY,
return rval; return rval;
%} %}
## Create a frontend interface to an existing master data store that allows function Broker::__create_frontend%(id: string%): opaque of Broker::Handle
## querying and updating its contents.
##
## id: the unique name which identifies the master data store.
##
## Returns: a handle to the data store.
function Broker::create_frontend%(id: string%): opaque of Broker::Handle
%{ %{
auto id_str = id->CheckString(); auto id_str = id->CheckString();
auto type = bro_broker::StoreType::FRONTEND; auto type = bro_broker::StoreType::FRONTEND;
@ -122,13 +85,7 @@ function Broker::create_frontend%(id: string%): opaque of Broker::Handle
return rval; return rval;
%} %}
## Close a data store. function Broker::__close_by_handle%(h: opaque of Broker::Handle%): bool
##
## h: a data store handle.
##
## Returns: true if store was valid and is now closed. The handle can no
## longer be used for data store operations.
function Broker::close_by_handle%(h: opaque of Broker::Handle%): bool
%{ %{
auto handle = static_cast<bro_broker::StoreHandleVal*>(h); auto handle = static_cast<bro_broker::StoreHandleVal*>(h);
@ -143,18 +100,7 @@ function Broker::close_by_handle%(h: opaque of Broker::Handle%): bool
# non-blocking update API # # non-blocking update API #
########################### ###########################
## Insert a key-value pair in to the store. function Broker::__insert%(h: opaque of Broker::Handle,
##
## h: the handle of the store to modify.
##
## k: the key to insert.
##
## v: the value to insert.
##
## e: the expiration time of the key-value pair.
##
## Returns: false if the store handle was not valid.
function Broker::insert%(h: opaque of Broker::Handle,
k: Broker::Data, v: Broker::Data, k: Broker::Data, v: Broker::Data,
e: Broker::ExpiryTime &default = Broker::ExpiryTime()%): bool e: Broker::ExpiryTime &default = Broker::ExpiryTime()%): bool
%{ %{
@ -191,14 +137,7 @@ function Broker::insert%(h: opaque of Broker::Handle,
return new Val(true, TYPE_BOOL); return new Val(true, TYPE_BOOL);
%} %}
## Remove a key-value pair from the store. function Broker::__erase%(h: opaque of Broker::Handle, k: Broker::Data%): bool
##
## h: the handle of the store to modify.
##
## k: the key to remove.
##
## Returns: false if the store handle was not valid.
function Broker::erase%(h: opaque of Broker::Handle, k: Broker::Data%): bool
%{ %{
auto handle = static_cast<bro_broker::StoreHandleVal*>(h); auto handle = static_cast<bro_broker::StoreHandleVal*>(h);
@ -210,12 +149,7 @@ function Broker::erase%(h: opaque of Broker::Handle, k: Broker::Data%): bool
return new Val(true, TYPE_BOOL); return new Val(true, TYPE_BOOL);
%} %}
## Remove all key-value pairs from the store. function Broker::__clear%(h: opaque of Broker::Handle%): bool
##
## h: the handle of the store to modify.
##
## Returns: false if the store handle was not valid.
function Broker::clear%(h: opaque of Broker::Handle%): bool
%{ %{
auto handle = static_cast<bro_broker::StoreHandleVal*>(h); auto handle = static_cast<bro_broker::StoreHandleVal*>(h);
@ -226,17 +160,7 @@ function Broker::clear%(h: opaque of Broker::Handle%): bool
return new Val(true, TYPE_BOOL); return new Val(true, TYPE_BOOL);
%} %}
## Increment an integer value in a data store. function Broker::__increment%(h: opaque of Broker::Handle,
##
## h: the handle of the store to modify.
##
## k: the key whose associated value is to be modified.
##
## by: the amount to increment the value by. A non-existent key will first
## create it with an implicit value of zero before incrementing.
##
## Returns: false if the store handle was not valid.
function Broker::increment%(h: opaque of Broker::Handle,
k: Broker::Data, by: int &default = +1%): bool k: Broker::Data, by: int &default = +1%): bool
%{ %{
auto handle = static_cast<bro_broker::StoreHandleVal*>(h); auto handle = static_cast<bro_broker::StoreHandleVal*>(h);
@ -249,17 +173,7 @@ function Broker::increment%(h: opaque of Broker::Handle,
return new Val(true, TYPE_BOOL); return new Val(true, TYPE_BOOL);
%} %}
## Decrement an integer value in a data store. function Broker::__decrement%(h: opaque of Broker::Handle,
##
## h: the handle of the store to modify.
##
## k: the key whose associated value is to be modified.
##
## by: the amount to decrement the value by. A non-existent key will first
## create it with an implicit value of zero before decrementing.
##
## Returns: false if the store handle was not valid.
function Broker::decrement%(h: opaque of Broker::Handle,
k: Broker::Data, by: int &default = +1%): bool k: Broker::Data, by: int &default = +1%): bool
%{ %{
auto handle = static_cast<bro_broker::StoreHandleVal*>(h); auto handle = static_cast<bro_broker::StoreHandleVal*>(h);
@ -272,17 +186,7 @@ function Broker::decrement%(h: opaque of Broker::Handle,
return new Val(true, TYPE_BOOL); return new Val(true, TYPE_BOOL);
%} %}
## Add an element to a set value in a data store. function Broker::__add_to_set%(h: opaque of Broker::Handle,
##
## h: the handle of the store to modify.
##
## k: the key whose associated value is to be modified.
##
## element: the element to add to the set. A non-existent key will first
## create it with an implicit empty set value before modifying.
##
## Returns: false if the store handle was not valid.
function Broker::add_to_set%(h: opaque of Broker::Handle,
k: Broker::Data, element: Broker::Data%): bool k: Broker::Data, element: Broker::Data%): bool
%{ %{
auto handle = static_cast<bro_broker::StoreHandleVal*>(h); auto handle = static_cast<bro_broker::StoreHandleVal*>(h);
@ -296,17 +200,7 @@ function Broker::add_to_set%(h: opaque of Broker::Handle,
return new Val(true, TYPE_BOOL); return new Val(true, TYPE_BOOL);
%} %}
## Remove an element from a set value in a data store. function Broker::__remove_from_set%(h: opaque of Broker::Handle,
##
## h: the handle of the store to modify.
##
## k: the key whose associated value is to be modified.
##
## element: the element to remove from the set. A non-existent key will
## implicitly create an empty set value associated with the key.
##
## Returns: false if the store handle was not valid.
function Broker::remove_from_set%(h: opaque of Broker::Handle,
k: Broker::Data, element: Broker::Data%): bool k: Broker::Data, element: Broker::Data%): bool
%{ %{
auto handle = static_cast<bro_broker::StoreHandleVal*>(h); auto handle = static_cast<bro_broker::StoreHandleVal*>(h);
@ -320,17 +214,7 @@ function Broker::remove_from_set%(h: opaque of Broker::Handle,
return new Val(true, TYPE_BOOL); return new Val(true, TYPE_BOOL);
%} %}
## Add a new item to the head of a vector value in a data store. function Broker::__push_left%(h: opaque of Broker::Handle, k: Broker::Data,
##
## h: the handle of store to modify.
##
## k: the key whose associated value is to be modified.
##
## items: the element to insert in to the vector. A non-existent key will first
## create an empty vector value before modifying.
##
## Returns: false if the store handle was not valid.
function Broker::push_left%(h: opaque of Broker::Handle, k: Broker::Data,
items: Broker::DataVector%): bool items: Broker::DataVector%): bool
%{ %{
auto handle = static_cast<bro_broker::StoreHandleVal*>(h); auto handle = static_cast<bro_broker::StoreHandleVal*>(h);
@ -353,17 +237,7 @@ function Broker::push_left%(h: opaque of Broker::Handle, k: Broker::Data,
return new Val(true, TYPE_BOOL); return new Val(true, TYPE_BOOL);
%} %}
## Add a new item to the tail of a vector value in a data store. function Broker::__push_right%(h: opaque of Broker::Handle, k: Broker::Data,
##
## h: the handle of store to modify.
##
## k: the key whose associated value is to be modified.
##
## items: the element to insert in to the vector. A non-existent key will first
## create an empty vector value before modifying.
##
## Returns: false if the store handle was not valid.
function Broker::push_right%(h: opaque of Broker::Handle, k: Broker::Data,
items: Broker::DataVector%): bool items: Broker::DataVector%): bool
%{ %{
auto handle = static_cast<bro_broker::StoreHandleVal*>(h); auto handle = static_cast<bro_broker::StoreHandleVal*>(h);
@ -437,14 +311,7 @@ static bool prepare_for_query(Val* opaque, Frame* frame,
%%} %%}
## Pop the head of a data store vector value. function Broker::__pop_left%(h: opaque of Broker::Handle,
##
## h: the handle of the store to query.
##
## k: the key associated with the vector to modify.
##
## Returns: the result of the query.
function Broker::pop_left%(h: opaque of Broker::Handle,
k: Broker::Data%): Broker::QueryResult k: Broker::Data%): Broker::QueryResult
%{ %{
if ( ! broker_mgr->Enabled() ) if ( ! broker_mgr->Enabled() )
@ -467,14 +334,7 @@ function Broker::pop_left%(h: opaque of Broker::Handle,
return 0; return 0;
%} %}
## Pop the tail of a data store vector value. function Broker::__pop_right%(h: opaque of Broker::Handle,
##
## h: the handle of the store to query.
##
## k: the key associated with the vector to modify.
##
## Returns: the result of the query.
function Broker::pop_right%(h: opaque of Broker::Handle,
k: Broker::Data%): Broker::QueryResult k: Broker::Data%): Broker::QueryResult
%{ %{
if ( ! broker_mgr->Enabled() ) if ( ! broker_mgr->Enabled() )
@ -497,14 +357,7 @@ function Broker::pop_right%(h: opaque of Broker::Handle,
return 0; return 0;
%} %}
## Lookup the value associated with a key in a data store. function Broker::__lookup%(h: opaque of Broker::Handle,
##
## h: the handle of the store to query.
##
## k: the key to lookup.
##
## Returns: the result of the query.
function Broker::lookup%(h: opaque of Broker::Handle,
k: Broker::Data%): Broker::QueryResult k: Broker::Data%): Broker::QueryResult
%{ %{
if ( ! broker_mgr->Enabled() ) if ( ! broker_mgr->Enabled() )
@ -527,14 +380,7 @@ function Broker::lookup%(h: opaque of Broker::Handle,
return 0; return 0;
%} %}
## Check if a data store contains a given key. function Broker::__exists%(h: opaque of Broker::Handle,
##
## h: the handle of the store to query.
##
## k: the key to check for existence.
##
## Returns: the result of the query (uses :bro:see:`Broker::BOOL`).
function Broker::exists%(h: opaque of Broker::Handle,
k: Broker::Data%): Broker::QueryResult k: Broker::Data%): Broker::QueryResult
%{ %{
if ( ! broker_mgr->Enabled() ) if ( ! broker_mgr->Enabled() )
@ -557,12 +403,7 @@ function Broker::exists%(h: opaque of Broker::Handle,
return 0; return 0;
%} %}
## Retrieve all keys in a data store. function Broker::__keys%(h: opaque of Broker::Handle%): Broker::QueryResult
##
## h: the handle of the store to query.
##
## Returns: the result of the query (uses :bro:see:`Broker::VECTOR`).
function Broker::keys%(h: opaque of Broker::Handle%): Broker::QueryResult
%{ %{
double timeout; double timeout;
bro_broker::StoreQueryCallback* cb; bro_broker::StoreQueryCallback* cb;
@ -575,12 +416,7 @@ function Broker::keys%(h: opaque of Broker::Handle%): Broker::QueryResult
return 0; return 0;
%} %}
## Get the number of key-value pairs in a data store. function Broker::__size%(h: opaque of Broker::Handle%): Broker::QueryResult
##
## h: the handle of the store to query.
##
## Returns: the result of the query (uses :bro:see:`Broker::COUNT`).
function Broker::size%(h: opaque of Broker::Handle%): Broker::QueryResult
%{ %{
if ( ! broker_mgr->Enabled() ) if ( ! broker_mgr->Enabled() )
return bro_broker::query_result(); return bro_broker::query_result();

View file

@ -30,12 +30,21 @@ hello
42.0 42.0
180.0 180.0
Broker::BOOL Broker::BOOL
***************************
{ {
two, two,
one, one,
three three
} }
{
[two] = 2,
[one] = 1,
[three] = 3
}
[zero, one, two]
[a=<uninitialized>, b=bee, c=1]
[a=test, b=bee, c=1]
[a=test, b=testagain, c=1]
***************************
0 0
T T
1 1
@ -43,19 +52,20 @@ T
F F
T T
2 2
F
2
T T
1 1
F F
{ {
bye bye
} }
T
0 0
***************************
{ {
[two] = 2,
[one] = 1,
[three] = 3
} }
***************************
0 0
[d=<uninitialized>] [d=<uninitialized>]
1 1
@ -69,8 +79,14 @@ F
37 37
[d=broker::data{42}] [d=broker::data{42}]
1 1
[d=<uninitialized>]
1
T
0
{
}
*************************** ***************************
[zero, one, two]
0 0
T T
T T
@ -85,10 +101,10 @@ T
[d=broker::data{bah}] [d=broker::data{bah}]
[hi, salutations, greetings] [hi, salutations, greetings]
3 3
T
0
[]
*************************** ***************************
[a=<uninitialized>, b=bee, c=1]
[a=test, b=bee, c=1]
[a=test, b=testagain, c=1]
3 3
T T
T T
@ -97,3 +113,6 @@ T
[d=broker::data{hello}] [d=broker::data{hello}]
[d=broker::data{37}] [d=broker::data{37}]
3 3
T
3
[d=broker::data{goodbye}]

View file

@ -30,12 +30,21 @@ hello
42.0 42.0
180.0 180.0
Broker::BOOL Broker::BOOL
***************************
{ {
two, two,
one, one,
three three
} }
{
[two] = 2,
[one] = 1,
[three] = 3
}
[zero, one, two]
[a=<uninitialized>, b=bee, c=1]
[a=test, b=bee, c=1]
[a=test, b=testagain, c=1]
***************************
0 0
T T
1 1
@ -43,19 +52,20 @@ T
F F
T T
2 2
F
2
T T
1 1
F F
{ {
bye bye
} }
T
0 0
***************************
{ {
[two] = 2,
[one] = 1,
[three] = 3
} }
***************************
0 0
[d=<uninitialized>] [d=<uninitialized>]
1 1
@ -69,8 +79,14 @@ F
37 37
[d=broker::data{42}] [d=broker::data{42}]
1 1
[d=<uninitialized>]
1
T
0
{
}
*************************** ***************************
[zero, one, two]
0 0
T T
T T
@ -85,10 +101,10 @@ T
[d=broker::data{bah}] [d=broker::data{bah}]
[hi, salutations, greetings] [hi, salutations, greetings]
3 3
T
0
[]
*************************** ***************************
[a=<uninitialized>, b=bee, c=1]
[a=test, b=bee, c=1]
[a=test, b=testagain, c=1]
3 3
T T
T T
@ -97,3 +113,6 @@ T
[d=broker::data{hello}] [d=broker::data{hello}]
[d=broker::data{37}] [d=broker::data{37}]
3 3
T
3
[d=broker::data{goodbye}]

View file

@ -17,7 +17,11 @@ scripts/base/init-bare.bro
build/scripts/base/bif/event.bif.bro build/scripts/base/bif/event.bif.bro
scripts/base/frameworks/broker/__load__.bro scripts/base/frameworks/broker/__load__.bro
scripts/base/frameworks/broker/main.bro scripts/base/frameworks/broker/main.bro
build/scripts/base/bif/comm.bif.bro
build/scripts/base/bif/messaging.bif.bro
scripts/base/frameworks/broker/store.bro scripts/base/frameworks/broker/store.bro
build/scripts/base/bif/data.bif.bro
build/scripts/base/bif/store.bif.bro
scripts/base/frameworks/logging/__load__.bro scripts/base/frameworks/logging/__load__.bro
scripts/base/frameworks/logging/main.bro scripts/base/frameworks/logging/main.bro
build/scripts/base/bif/logging.bif.bro build/scripts/base/bif/logging.bif.bro
@ -51,10 +55,6 @@ scripts/base/init-bare.bro
build/scripts/base/bif/bloom-filter.bif.bro build/scripts/base/bif/bloom-filter.bif.bro
build/scripts/base/bif/cardinality-counter.bif.bro build/scripts/base/bif/cardinality-counter.bif.bro
build/scripts/base/bif/top-k.bif.bro build/scripts/base/bif/top-k.bif.bro
build/scripts/base/bif/comm.bif.bro
build/scripts/base/bif/data.bif.bro
build/scripts/base/bif/messaging.bif.bro
build/scripts/base/bif/store.bif.bro
build/scripts/base/bif/plugins/__load__.bro build/scripts/base/bif/plugins/__load__.bro
build/scripts/base/bif/plugins/Bro_ARP.events.bif.bro build/scripts/base/bif/plugins/Bro_ARP.events.bif.bro
build/scripts/base/bif/plugins/Bro_AYIYA.events.bif.bro build/scripts/base/bif/plugins/Bro_AYIYA.events.bif.bro

View file

@ -17,7 +17,11 @@ scripts/base/init-bare.bro
build/scripts/base/bif/event.bif.bro build/scripts/base/bif/event.bif.bro
scripts/base/frameworks/broker/__load__.bro scripts/base/frameworks/broker/__load__.bro
scripts/base/frameworks/broker/main.bro scripts/base/frameworks/broker/main.bro
build/scripts/base/bif/comm.bif.bro
build/scripts/base/bif/messaging.bif.bro
scripts/base/frameworks/broker/store.bro scripts/base/frameworks/broker/store.bro
build/scripts/base/bif/data.bif.bro
build/scripts/base/bif/store.bif.bro
scripts/base/frameworks/logging/__load__.bro scripts/base/frameworks/logging/__load__.bro
scripts/base/frameworks/logging/main.bro scripts/base/frameworks/logging/main.bro
build/scripts/base/bif/logging.bif.bro build/scripts/base/bif/logging.bif.bro
@ -51,10 +55,6 @@ scripts/base/init-bare.bro
build/scripts/base/bif/bloom-filter.bif.bro build/scripts/base/bif/bloom-filter.bif.bro
build/scripts/base/bif/cardinality-counter.bif.bro build/scripts/base/bif/cardinality-counter.bif.bro
build/scripts/base/bif/top-k.bif.bro build/scripts/base/bif/top-k.bif.bro
build/scripts/base/bif/comm.bif.bro
build/scripts/base/bif/data.bif.bro
build/scripts/base/bif/messaging.bif.bro
build/scripts/base/bif/store.bif.bro
build/scripts/base/bif/plugins/__load__.bro build/scripts/base/bif/plugins/__load__.bro
build/scripts/base/bif/plugins/Bro_ARP.events.bif.bro build/scripts/base/bif/plugins/Bro_ARP.events.bif.bro
build/scripts/base/bif/plugins/Bro_AYIYA.events.bif.bro build/scripts/base/bif/plugins/Bro_AYIYA.events.bif.bro

View file

@ -21,11 +21,11 @@ event Broker::outgoing_connection_established(peer_address: string,
{ {
print "Broker::outgoing_connection_established", print "Broker::outgoing_connection_established",
peer_address, peer_port, peer_name; peer_address, peer_port, peer_name;
Broker::event("bro/event/my_event", Broker::event_args(my_event, "hi", 0)); Broker::send_event("bro/event/my_event", Broker::event_args(my_event, "hi", 0));
event my_auto_event("stuff", 88); event my_auto_event("stuff", 88);
Broker::event("bro/event/my_event", Broker::event_args(my_event, "...", 1)); Broker::send_event("bro/event/my_event", Broker::event_args(my_event, "...", 1));
event my_auto_event("more stuff", 51); event my_auto_event("more stuff", 51);
Broker::event("bro/event/my_event", Broker::event_args(my_event, "bye", 2)); Broker::send_event("bro/event/my_event", Broker::event_args(my_event, "bye", 2));
} }
event Broker::outgoing_connection_broken(peer_address: string, event Broker::outgoing_connection_broken(peer_address: string,

View file

@ -18,9 +18,9 @@ event Broker::outgoing_connection_established(peer_address: string,
{ {
print "Broker::outgoing_connection_established", print "Broker::outgoing_connection_established",
peer_address, peer_port, peer_name; peer_address, peer_port, peer_name;
Broker::print("bro/print/hi", "hello"); Broker::send_print("bro/print/hi", "hello");
Broker::print("bro/print/stuff", "..."); Broker::send_print("bro/print/stuff", "...");
Broker::print("bro/print/bye", "goodbye"); Broker::send_print("bro/print/bye", "goodbye");
} }
event Broker::outgoing_connection_broken(peer_address: string, event Broker::outgoing_connection_broken(peer_address: string,

View file

@ -1,8 +1,8 @@
# @TEST-SERIALIZE: brokercomm # @TEST-SERIALIZE: brokercomm
# @TEST-REQUIRES: grep -q ENABLE_BROKER $BUILD/CMakeCache.txt # @TEST-REQUIRES: grep -q ENABLE_BROKER $BUILD/CMakeCache.txt
# @TEST-EXEC: btest-bg-run clone "bro -b -r $TRACES/wikipedia.trace ../clone.bro broker_port=$BROKER_PORT >clone.out" # @TEST-EXEC: btest-bg-run clone "bro -b ../clone.bro broker_port=$BROKER_PORT >clone.out"
# @TEST-EXEC: btest-bg-run master "bro -b -r $TRACES/wikipedia.trace ../master.bro broker_port=$BROKER_PORT >master.out" # @TEST-EXEC: btest-bg-run master "bro -b ../master.bro broker_port=$BROKER_PORT >master.out"
# @TEST-EXEC: btest-bg-wait 60 # @TEST-EXEC: btest-bg-wait 60
# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-sort btest-diff clone/clone.out # @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-sort btest-diff clone/clone.out

View file

@ -22,12 +22,12 @@ event bro_init()
event Broker::incoming_connection_established(peer_name: string) event Broker::incoming_connection_established(peer_name: string)
{ {
print "Broker::incoming_connection_established", peer_name;; print "Broker::incoming_connection_established", peer_name;
} }
event Broker::incoming_connection_broken(peer_name: string) event Broker::incoming_connection_broken(peer_name: string)
{ {
print "Broker::incoming_connection_broken", peer_name;; print "Broker::incoming_connection_broken", peer_name;
terminate(); terminate();
} }
@ -50,7 +50,7 @@ event Broker::outgoing_connection_established(peer_address: string,
peer_name: string) peer_name: string)
{ {
print "Broker::outgoing_connection_established", print "Broker::outgoing_connection_established",
peer_address, peer_port, peer_name;; peer_address, peer_port, peer_name;
terminate(); terminate();
} }

View file

@ -13,7 +13,7 @@ type bro_record : record {
c: count; c: count;
}; };
function comm_record_to_bro_record_recurse(it: opaque of Broker::RecordIterator, function broker_to_bro_record_recurse(it: opaque of Broker::RecordIterator,
rval: bro_record, rval: bro_record,
idx: count): bro_record idx: count): bro_record
{ {
@ -37,17 +37,17 @@ function comm_record_to_bro_record_recurse(it: opaque of Broker::RecordIterator,
++idx; ++idx;
Broker::record_iterator_next(it); Broker::record_iterator_next(it);
return comm_record_to_bro_record_recurse(it, rval, idx); return broker_to_bro_record_recurse(it, rval, idx);
} }
function comm_record_to_bro_record(d: Broker::Data): bro_record function broker_to_bro_record(d: Broker::Data): bro_record
{ {
return comm_record_to_bro_record_recurse(Broker::record_iterator(d), return broker_to_bro_record_recurse(Broker::record_iterator(d),
bro_record($c = 0), 0); bro_record($c = 0), 0);
} }
function function
comm_set_to_bro_set_recurse(it: opaque of Broker::SetIterator, broker_to_bro_set_recurse(it: opaque of Broker::SetIterator,
rval: bro_set): bro_set rval: bro_set): bro_set
{ {
if ( Broker::set_iterator_last(it) ) if ( Broker::set_iterator_last(it) )
@ -55,17 +55,17 @@ comm_set_to_bro_set_recurse(it: opaque of Broker::SetIterator,
add rval[Broker::refine_to_string(Broker::set_iterator_value(it))]; add rval[Broker::refine_to_string(Broker::set_iterator_value(it))];
Broker::set_iterator_next(it); Broker::set_iterator_next(it);
return comm_set_to_bro_set_recurse(it, rval); return broker_to_bro_set_recurse(it, rval);
} }
function comm_set_to_bro_set(d: Broker::Data): bro_set function broker_to_bro_set(d: Broker::Data): bro_set
{ {
return comm_set_to_bro_set_recurse(Broker::set_iterator(d), bro_set()); return broker_to_bro_set_recurse(Broker::set_iterator(d), bro_set());
} }
function function
comm_table_to_bro_table_recurse(it: opaque of Broker::TableIterator, broker_to_bro_table_recurse(it: opaque of Broker::TableIterator,
rval: bro_table): bro_table rval: bro_table): bro_table
{ {
if ( Broker::table_iterator_last(it) ) if ( Broker::table_iterator_last(it) )
@ -74,16 +74,16 @@ comm_table_to_bro_table_recurse(it: opaque of Broker::TableIterator,
local item = Broker::table_iterator_value(it); local item = Broker::table_iterator_value(it);
rval[Broker::refine_to_string(item$key)] = Broker::refine_to_count(item$val); rval[Broker::refine_to_string(item$key)] = Broker::refine_to_count(item$val);
Broker::table_iterator_next(it); Broker::table_iterator_next(it);
return comm_table_to_bro_table_recurse(it, rval); return broker_to_bro_table_recurse(it, rval);
} }
function comm_table_to_bro_table(d: Broker::Data): bro_table function broker_to_bro_table(d: Broker::Data): bro_table
{ {
return comm_table_to_bro_table_recurse(Broker::table_iterator(d), return broker_to_bro_table_recurse(Broker::table_iterator(d),
bro_table()); bro_table());
} }
function comm_vector_to_bro_vector_recurse(it: opaque of Broker::VectorIterator, function broker_to_bro_vector_recurse(it: opaque of Broker::VectorIterator,
rval: bro_vector): bro_vector rval: bro_vector): bro_vector
{ {
if ( Broker::vector_iterator_last(it) ) if ( Broker::vector_iterator_last(it) )
@ -91,18 +91,21 @@ function comm_vector_to_bro_vector_recurse(it: opaque of Broker::VectorIterator,
rval[|rval|] = Broker::refine_to_string(Broker::vector_iterator_value(it)); rval[|rval|] = Broker::refine_to_string(Broker::vector_iterator_value(it));
Broker::vector_iterator_next(it); Broker::vector_iterator_next(it);
return comm_vector_to_bro_vector_recurse(it, rval); return broker_to_bro_vector_recurse(it, rval);
} }
function comm_vector_to_bro_vector(d: Broker::Data): bro_vector function broker_to_bro_vector(d: Broker::Data): bro_vector
{ {
return comm_vector_to_bro_vector_recurse(Broker::vector_iterator(d), return broker_to_bro_vector_recurse(Broker::vector_iterator(d),
bro_vector()); bro_vector());
} }
event bro_init() event bro_init()
{ {
Broker::enable(); Broker::enable();
### Print every broker data type
print Broker::data_type(Broker::data(T)); print Broker::data_type(Broker::data(T));
print Broker::data_type(Broker::data(+1)); print Broker::data_type(Broker::data(+1));
print Broker::data_type(Broker::data(1)); print Broker::data_type(Broker::data(1));
@ -125,6 +128,8 @@ print Broker::data_type(Broker::data(r));
print "***************************"; print "***************************";
### Convert a Bro value to a broker value, then print the result
print Broker::refine_to_bool(Broker::data(T)); print Broker::refine_to_bool(Broker::data(T));
print Broker::refine_to_bool(Broker::data(F)); print Broker::refine_to_bool(Broker::data(F));
print Broker::refine_to_int(Broker::data(+1)); print Broker::refine_to_int(Broker::data(+1));
@ -142,10 +147,30 @@ print Broker::refine_to_time(Broker::data(double_to_time(42)));
print Broker::refine_to_interval(Broker::data(3min)); print Broker::refine_to_interval(Broker::data(3min));
print Broker::refine_to_enum_name(Broker::data(Broker::BOOL)); print Broker::refine_to_enum_name(Broker::data(Broker::BOOL));
local cs = Broker::data(s);
print broker_to_bro_set(cs);
local ct = Broker::data(t);
print broker_to_bro_table(ct);
local cv = Broker::data(v);
print broker_to_bro_vector(cv);
local cr = Broker::data(r);
print broker_to_bro_record(cr);
r$a = "test";
cr = Broker::data(r);
print broker_to_bro_record(cr);
r$b = "testagain";
cr = Broker::data(r);
print broker_to_bro_record(cr);
print "***************************"; print "***************************";
local cs = Broker::data(s); ### Test the broker set BIFs
print comm_set_to_bro_set(cs);
cs = Broker::set_create(); cs = Broker::set_create();
print Broker::set_size(cs); print Broker::set_size(cs);
print Broker::set_insert(cs, Broker::data("hi")); print Broker::set_insert(cs, Broker::data("hi"));
@ -154,17 +179,20 @@ print Broker::set_contains(cs, Broker::data("hi"));
print Broker::set_contains(cs, Broker::data("bye")); print Broker::set_contains(cs, Broker::data("bye"));
print Broker::set_insert(cs, Broker::data("bye")); print Broker::set_insert(cs, Broker::data("bye"));
print Broker::set_size(cs); print Broker::set_size(cs);
print Broker::set_insert(cs, Broker::data("bye"));
print Broker::set_size(cs);
print Broker::set_remove(cs, Broker::data("hi")); print Broker::set_remove(cs, Broker::data("hi"));
print Broker::set_size(cs); print Broker::set_size(cs);
print Broker::set_remove(cs, Broker::data("hi")); print Broker::set_remove(cs, Broker::data("hi"));
print comm_set_to_bro_set(cs); print broker_to_bro_set(cs);
Broker::set_clear(cs); print Broker::set_clear(cs);
print Broker::set_size(cs); print Broker::set_size(cs);
print broker_to_bro_set(cs);
print "***************************"; print "***************************";
local ct = Broker::data(t); ### Test the broker table BIFs
print comm_table_to_bro_table(ct);
ct = Broker::table_create(); ct = Broker::table_create();
print Broker::table_size(ct); print Broker::table_size(ct);
print Broker::table_insert(ct, Broker::data("hi"), Broker::data(42)); print Broker::table_insert(ct, Broker::data("hi"), Broker::data(42));
@ -179,37 +207,39 @@ print Broker::table_size(ct);
print Broker::refine_to_count(Broker::table_lookup(ct, Broker::data("bye"))); print Broker::refine_to_count(Broker::table_lookup(ct, Broker::data("bye")));
print Broker::table_remove(ct, Broker::data("hi")); print Broker::table_remove(ct, Broker::data("hi"));
print Broker::table_size(ct); print Broker::table_size(ct);
print Broker::table_remove(ct, Broker::data("hi"));
print Broker::table_size(ct);
print Broker::table_clear(ct);
print Broker::table_size(ct);
print broker_to_bro_table(ct);
print "***************************"; print "***************************";
local cv = Broker::data(v); ### Test the broker vector BIFs
print comm_vector_to_bro_vector(cv);
cv = Broker::vector_create(); cv = Broker::vector_create();
print Broker::vector_size(cv); print Broker::vector_size(cv);
print Broker::vector_insert(cv, Broker::data("hi"), 0); print Broker::vector_insert(cv, Broker::data("hi"), 0);
print Broker::vector_insert(cv, Broker::data("hello"), 1); print Broker::vector_insert(cv, Broker::data("hello"), 1);
print Broker::vector_insert(cv, Broker::data("greetings"), 2); print Broker::vector_insert(cv, Broker::data("greetings"), 2);
print Broker::vector_insert(cv, Broker::data("salutations"), 1); print Broker::vector_insert(cv, Broker::data("salutations"), 1);
print comm_vector_to_bro_vector(cv); print broker_to_bro_vector(cv);
print Broker::vector_size(cv); print Broker::vector_size(cv);
print Broker::vector_replace(cv, Broker::data("bah"), 2); print Broker::vector_replace(cv, Broker::data("bah"), 2);
print Broker::vector_lookup(cv, 2); print Broker::vector_lookup(cv, 2);
print Broker::vector_lookup(cv, 0); print Broker::vector_lookup(cv, 0);
print comm_vector_to_bro_vector(cv); print broker_to_bro_vector(cv);
print Broker::vector_remove(cv, 2); print Broker::vector_remove(cv, 2);
print comm_vector_to_bro_vector(cv); print broker_to_bro_vector(cv);
print Broker::vector_size(cv); print Broker::vector_size(cv);
print Broker::vector_clear(cv);
print Broker::vector_size(cv);
print broker_to_bro_vector(cv);
print "***************************"; print "***************************";
local cr = Broker::data(r); ### Test the broker record BIFs
print comm_record_to_bro_record(cr);
r$a = "test";
cr = Broker::data(r);
print comm_record_to_bro_record(cr);
r$b = "testagain";
cr = Broker::data(r);
print comm_record_to_bro_record(cr);
cr = Broker::record_create(3); cr = Broker::record_create(3);
print Broker::record_size(cr); print Broker::record_size(cr);
print Broker::record_assign(cr, Broker::data("hi"), 0); print Broker::record_assign(cr, Broker::data("hi"), 0);
@ -219,4 +249,7 @@ print Broker::record_lookup(cr, 0);
print Broker::record_lookup(cr, 1); print Broker::record_lookup(cr, 1);
print Broker::record_lookup(cr, 2); print Broker::record_lookup(cr, 2);
print Broker::record_size(cr); print Broker::record_size(cr);
print Broker::record_assign(cr, Broker::data("goodbye"), 1);
print Broker::record_size(cr);
print Broker::record_lookup(cr, 1);
} }

View file

@ -40,7 +40,7 @@ event event_handler(msg: string, n: count)
event auto_event_handler(msg, n); event auto_event_handler(msg, n);
local args = Broker::event_args(event_handler, "pong", n); local args = Broker::event_args(event_handler, "pong", n);
Broker::event("bro/event/my_topic", args); Broker::send_event("bro/event/my_topic", args);
} }
@TEST-END-FILE @TEST-END-FILE
@ -68,7 +68,7 @@ event Broker::outgoing_connection_established(peer_address: string,
{ {
print "Broker::outgoing_connection_established", peer_address, peer_port; print "Broker::outgoing_connection_established", peer_address, peer_port;
local args = Broker::event_args(event_handler, "ping", event_count); local args = Broker::event_args(event_handler, "ping", event_count);
Broker::event("bro/event/hi", args); Broker::send_event("bro/event/hi", args);
++event_count; ++event_count;
} }
@ -82,7 +82,7 @@ event event_handler(msg: string, n: count)
{ {
print "got event msg", msg, n; print "got event msg", msg, n;
local args = Broker::event_args(event_handler, "ping", event_count); local args = Broker::event_args(event_handler, "ping", event_count);
Broker::event("bro/event/hi", args); Broker::send_event("bro/event/hi", args);
++event_count; ++event_count;
} }

View file

@ -16,8 +16,8 @@ redef exit_only_after_terminate = T;
event bro_init() event bro_init()
{ {
Broker::enable(); Broker::enable();
Broker::listen(broker_port, "127.0.0.1");
Broker::subscribe_to_prints("bro/print/"); Broker::subscribe_to_prints("bro/print/");
Broker::listen(broker_port, "127.0.0.1");
} }
global messages_to_recv = 6; global messages_to_recv = 6;
@ -35,7 +35,7 @@ event Broker::print_handler(msg: string)
return; return;
} }
Broker::print("bro/print/my_topic", fmt("pong %d", messages_sent)); Broker::send_print("bro/print/my_topic", fmt("pong %d", messages_sent));
++messages_sent; ++messages_sent;
} }
@ -62,7 +62,7 @@ event Broker::outgoing_connection_established(peer_address: string,
peer_name: string) peer_name: string)
{ {
print "Broker::outgoing_connection_established", peer_address, peer_port; print "Broker::outgoing_connection_established", peer_address, peer_port;
Broker::print("bro/print/hi", fmt("ping %d", messages_sent)); Broker::send_print("bro/print/hi", fmt("ping %d", messages_sent));
++messages_sent; ++messages_sent;
} }
@ -76,7 +76,7 @@ event Broker::print_handler(msg: string)
{ {
++messages_recv; ++messages_recv;
print "got print msg", msg; print "got print msg", msg;
Broker::print("bro/print/hi", fmt("ping %d", messages_sent)); Broker::send_print("bro/print/hi", fmt("ping %d", messages_sent));
++messages_sent; ++messages_sent;
} }

View file

@ -51,8 +51,8 @@ event ready()
event bro_init() event bro_init()
{ {
Broker::enable(); Broker::enable();
Broker::listen(broker_port, "127.0.0.1");
Broker::subscribe_to_events("bro/event/ready"); Broker::subscribe_to_events("bro/event/ready");
Broker::listen(broker_port, "127.0.0.1");
} }
@TEST-END-FILE @TEST-END-FILE
@ -105,9 +105,9 @@ event Broker::outgoing_connection_established(peer_address: string,
event bro_init() event bro_init()
{ {
Broker::enable(); Broker::enable();
Broker::auto_event("bro/event/ready", ready);
h = Broker::create_master("mystore"); h = Broker::create_master("mystore");
Broker::connect("127.0.0.1", broker_port, 1secs); Broker::connect("127.0.0.1", broker_port, 1secs);
Broker::auto_event("bro/event/ready", ready);
} }
@TEST-END-FILE @TEST-END-FILE

View file

@ -16,7 +16,7 @@ type bro_record : record {
c: count; c: count;
}; };
function comm_record_to_bro_record_recurse(it: opaque of Broker::RecordIterator, function broker_to_bro_record_recurse(it: opaque of Broker::RecordIterator,
rval: bro_record, rval: bro_record,
idx: count): bro_record idx: count): bro_record
{ {
@ -40,17 +40,17 @@ function comm_record_to_bro_record_recurse(it: opaque of Broker::RecordIterator,
++idx; ++idx;
Broker::record_iterator_next(it); Broker::record_iterator_next(it);
return comm_record_to_bro_record_recurse(it, rval, idx); return broker_to_bro_record_recurse(it, rval, idx);
} }
function comm_record_to_bro_record(d: Broker::Data): bro_record function broker_to_bro_record(d: Broker::Data): bro_record
{ {
return comm_record_to_bro_record_recurse(Broker::record_iterator(d), return broker_to_bro_record_recurse(Broker::record_iterator(d),
bro_record($c = 0), 0); bro_record($c = 0), 0);
} }
function function
comm_set_to_bro_set_recurse(it: opaque of Broker::SetIterator, broker_to_bro_set_recurse(it: opaque of Broker::SetIterator,
rval: bro_set): bro_set rval: bro_set): bro_set
{ {
if ( Broker::set_iterator_last(it) ) if ( Broker::set_iterator_last(it) )
@ -58,17 +58,17 @@ comm_set_to_bro_set_recurse(it: opaque of Broker::SetIterator,
add rval[Broker::refine_to_string(Broker::set_iterator_value(it))]; add rval[Broker::refine_to_string(Broker::set_iterator_value(it))];
Broker::set_iterator_next(it); Broker::set_iterator_next(it);
return comm_set_to_bro_set_recurse(it, rval); return broker_to_bro_set_recurse(it, rval);
} }
function comm_set_to_bro_set(d: Broker::Data): bro_set function broker_to_bro_set(d: Broker::Data): bro_set
{ {
return comm_set_to_bro_set_recurse(Broker::set_iterator(d), bro_set()); return broker_to_bro_set_recurse(Broker::set_iterator(d), bro_set());
} }
function function
comm_table_to_bro_table_recurse(it: opaque of Broker::TableIterator, broker_to_bro_table_recurse(it: opaque of Broker::TableIterator,
rval: bro_table): bro_table rval: bro_table): bro_table
{ {
if ( Broker::table_iterator_last(it) ) if ( Broker::table_iterator_last(it) )
@ -77,16 +77,16 @@ comm_table_to_bro_table_recurse(it: opaque of Broker::TableIterator,
local item = Broker::table_iterator_value(it); local item = Broker::table_iterator_value(it);
rval[Broker::refine_to_string(item$key)] = Broker::refine_to_count(item$val); rval[Broker::refine_to_string(item$key)] = Broker::refine_to_count(item$val);
Broker::table_iterator_next(it); Broker::table_iterator_next(it);
return comm_table_to_bro_table_recurse(it, rval); return broker_to_bro_table_recurse(it, rval);
} }
function comm_table_to_bro_table(d: Broker::Data): bro_table function broker_to_bro_table(d: Broker::Data): bro_table
{ {
return comm_table_to_bro_table_recurse(Broker::table_iterator(d), return broker_to_bro_table_recurse(Broker::table_iterator(d),
bro_table()); bro_table());
} }
function comm_vector_to_bro_vector_recurse(it: opaque of Broker::VectorIterator, function broker_to_bro_vector_recurse(it: opaque of Broker::VectorIterator,
rval: bro_vector): bro_vector rval: bro_vector): bro_vector
{ {
if ( Broker::vector_iterator_last(it) ) if ( Broker::vector_iterator_last(it) )
@ -94,26 +94,29 @@ function comm_vector_to_bro_vector_recurse(it: opaque of Broker::VectorIterator,
rval[|rval|] = Broker::refine_to_string(Broker::vector_iterator_value(it)); rval[|rval|] = Broker::refine_to_string(Broker::vector_iterator_value(it));
Broker::vector_iterator_next(it); Broker::vector_iterator_next(it);
return comm_vector_to_bro_vector_recurse(it, rval); return broker_to_bro_vector_recurse(it, rval);
} }
function comm_vector_to_bro_vector(d: Broker::Data): bro_vector function broker_to_bro_vector(d: Broker::Data): bro_vector
{ {
return comm_vector_to_bro_vector_recurse(Broker::vector_iterator(d), return broker_to_bro_vector_recurse(Broker::vector_iterator(d),
bro_vector()); bro_vector());
} }
event bro_init() event bro_init()
{ {
Broker::enable(); Broker::enable();
} }
global did_it = F; global did_it = F;
event new_connection(c: connection) event new_connection(c: connection)
{ {
if ( did_it ) return; if ( did_it ) return;
did_it = T; did_it = T;
### Print every broker data type
print Broker::data_type(Broker::data(T)); print Broker::data_type(Broker::data(T));
print Broker::data_type(Broker::data(+1)); print Broker::data_type(Broker::data(+1));
print Broker::data_type(Broker::data(1)); print Broker::data_type(Broker::data(1));
@ -136,6 +139,8 @@ print Broker::data_type(Broker::data(r));
print "***************************"; print "***************************";
### Convert a Bro value to a broker value, then print the result
print Broker::refine_to_bool(Broker::data(T)); print Broker::refine_to_bool(Broker::data(T));
print Broker::refine_to_bool(Broker::data(F)); print Broker::refine_to_bool(Broker::data(F));
print Broker::refine_to_int(Broker::data(+1)); print Broker::refine_to_int(Broker::data(+1));
@ -153,10 +158,30 @@ print Broker::refine_to_time(Broker::data(double_to_time(42)));
print Broker::refine_to_interval(Broker::data(3min)); print Broker::refine_to_interval(Broker::data(3min));
print Broker::refine_to_enum_name(Broker::data(Broker::BOOL)); print Broker::refine_to_enum_name(Broker::data(Broker::BOOL));
local cs = Broker::data(s);
print broker_to_bro_set(cs);
local ct = Broker::data(t);
print broker_to_bro_table(ct);
local cv = Broker::data(v);
print broker_to_bro_vector(cv);
local cr = Broker::data(r);
print broker_to_bro_record(cr);
r$a = "test";
cr = Broker::data(r);
print broker_to_bro_record(cr);
r$b = "testagain";
cr = Broker::data(r);
print broker_to_bro_record(cr);
print "***************************"; print "***************************";
local cs = Broker::data(s); ### Test the broker set BIFs
print comm_set_to_bro_set(cs);
cs = Broker::set_create(); cs = Broker::set_create();
print Broker::set_size(cs); print Broker::set_size(cs);
print Broker::set_insert(cs, Broker::data("hi")); print Broker::set_insert(cs, Broker::data("hi"));
@ -165,17 +190,20 @@ print Broker::set_contains(cs, Broker::data("hi"));
print Broker::set_contains(cs, Broker::data("bye")); print Broker::set_contains(cs, Broker::data("bye"));
print Broker::set_insert(cs, Broker::data("bye")); print Broker::set_insert(cs, Broker::data("bye"));
print Broker::set_size(cs); print Broker::set_size(cs);
print Broker::set_insert(cs, Broker::data("bye"));
print Broker::set_size(cs);
print Broker::set_remove(cs, Broker::data("hi")); print Broker::set_remove(cs, Broker::data("hi"));
print Broker::set_size(cs); print Broker::set_size(cs);
print Broker::set_remove(cs, Broker::data("hi")); print Broker::set_remove(cs, Broker::data("hi"));
print comm_set_to_bro_set(cs); print broker_to_bro_set(cs);
Broker::set_clear(cs); print Broker::set_clear(cs);
print Broker::set_size(cs); print Broker::set_size(cs);
print broker_to_bro_set(cs);
print "***************************"; print "***************************";
local ct = Broker::data(t); ### Test the broker table BIFs
print comm_table_to_bro_table(ct);
ct = Broker::table_create(); ct = Broker::table_create();
print Broker::table_size(ct); print Broker::table_size(ct);
print Broker::table_insert(ct, Broker::data("hi"), Broker::data(42)); print Broker::table_insert(ct, Broker::data("hi"), Broker::data(42));
@ -190,37 +218,39 @@ print Broker::table_size(ct);
print Broker::refine_to_count(Broker::table_lookup(ct, Broker::data("bye"))); print Broker::refine_to_count(Broker::table_lookup(ct, Broker::data("bye")));
print Broker::table_remove(ct, Broker::data("hi")); print Broker::table_remove(ct, Broker::data("hi"));
print Broker::table_size(ct); print Broker::table_size(ct);
print Broker::table_remove(ct, Broker::data("hi"));
print Broker::table_size(ct);
print Broker::table_clear(ct);
print Broker::table_size(ct);
print broker_to_bro_table(ct);
print "***************************"; print "***************************";
local cv = Broker::data(v); ### Test the broker vector BIFs
print comm_vector_to_bro_vector(cv);
cv = Broker::vector_create(); cv = Broker::vector_create();
print Broker::vector_size(cv); print Broker::vector_size(cv);
print Broker::vector_insert(cv, Broker::data("hi"), 0); print Broker::vector_insert(cv, Broker::data("hi"), 0);
print Broker::vector_insert(cv, Broker::data("hello"), 1); print Broker::vector_insert(cv, Broker::data("hello"), 1);
print Broker::vector_insert(cv, Broker::data("greetings"), 2); print Broker::vector_insert(cv, Broker::data("greetings"), 2);
print Broker::vector_insert(cv, Broker::data("salutations"), 1); print Broker::vector_insert(cv, Broker::data("salutations"), 1);
print comm_vector_to_bro_vector(cv); print broker_to_bro_vector(cv);
print Broker::vector_size(cv); print Broker::vector_size(cv);
print Broker::vector_replace(cv, Broker::data("bah"), 2); print Broker::vector_replace(cv, Broker::data("bah"), 2);
print Broker::vector_lookup(cv, 2); print Broker::vector_lookup(cv, 2);
print Broker::vector_lookup(cv, 0); print Broker::vector_lookup(cv, 0);
print comm_vector_to_bro_vector(cv); print broker_to_bro_vector(cv);
print Broker::vector_remove(cv, 2); print Broker::vector_remove(cv, 2);
print comm_vector_to_bro_vector(cv); print broker_to_bro_vector(cv);
print Broker::vector_size(cv); print Broker::vector_size(cv);
print Broker::vector_clear(cv);
print Broker::vector_size(cv);
print broker_to_bro_vector(cv);
print "***************************"; print "***************************";
local cr = Broker::data(r); ### Test the broker record BIFs
print comm_record_to_bro_record(cr);
r$a = "test";
cr = Broker::data(r);
print comm_record_to_bro_record(cr);
r$b = "testagain";
cr = Broker::data(r);
print comm_record_to_bro_record(cr);
cr = Broker::record_create(3); cr = Broker::record_create(3);
print Broker::record_size(cr); print Broker::record_size(cr);
print Broker::record_assign(cr, Broker::data("hi"), 0); print Broker::record_assign(cr, Broker::data("hi"), 0);
@ -230,4 +260,7 @@ print Broker::record_lookup(cr, 0);
print Broker::record_lookup(cr, 1); print Broker::record_lookup(cr, 1);
print Broker::record_lookup(cr, 2); print Broker::record_lookup(cr, 2);
print Broker::record_size(cr); print Broker::record_size(cr);
print Broker::record_assign(cr, Broker::data("goodbye"), 1);
print Broker::record_size(cr);
print Broker::record_lookup(cr, 1);
} }

View file

@ -21,9 +21,9 @@ global auto_event_handler: event(msg: string, c: count);
event bro_init() event bro_init()
{ {
Broker::enable(); Broker::enable();
Broker::listen(broker_port, "127.0.0.1");
Broker::subscribe_to_events("bro/event/"); Broker::subscribe_to_events("bro/event/");
Broker::auto_event("bro/event/my_topic", auto_event_handler); Broker::auto_event("bro/event/my_topic", auto_event_handler);
Broker::listen(broker_port, "127.0.0.1");
} }
global event_count = 0; global event_count = 0;
@ -42,7 +42,7 @@ event event_handler(msg: string, n: count)
event auto_event_handler(msg, n); event auto_event_handler(msg, n);
local args = Broker::event_args(event_handler, "pong", n); local args = Broker::event_args(event_handler, "pong", n);
Broker::event("bro/event/my_topic", args); Broker::send_event("bro/event/my_topic", args);
} }
@TEST-END-FILE @TEST-END-FILE
@ -70,7 +70,7 @@ event Broker::outgoing_connection_established(peer_address: string,
{ {
print "Broker::outgoing_connection_established", peer_address, peer_port; print "Broker::outgoing_connection_established", peer_address, peer_port;
local args = Broker::event_args(event_handler, "ping", event_count); local args = Broker::event_args(event_handler, "ping", event_count);
Broker::event("bro/event/hi", args); Broker::send_event("bro/event/hi", args);
++event_count; ++event_count;
} }
@ -84,7 +84,7 @@ event event_handler(msg: string, n: count)
{ {
print "got event msg", msg, n; print "got event msg", msg, n;
local args = Broker::event_args(event_handler, "ping", event_count); local args = Broker::event_args(event_handler, "ping", event_count);
Broker::event("bro/event/hi", args); Broker::send_event("bro/event/hi", args);
++event_count; ++event_count;
} }

View file

@ -42,8 +42,8 @@ redef exit_only_after_terminate = T;
event bro_init() event bro_init()
{ {
Broker::listen(broker_port, "127.0.0.1");
Broker::subscribe_to_logs("bro/log/"); Broker::subscribe_to_logs("bro/log/");
Broker::listen(broker_port, "127.0.0.1");
} }
event Test::log_test(rec: Test::Info) event Test::log_test(rec: Test::Info)

View file

@ -18,8 +18,8 @@ redef exit_only_after_terminate = T;
event bro_init() event bro_init()
{ {
Broker::enable(); Broker::enable();
Broker::listen(broker_port, "127.0.0.1");
Broker::subscribe_to_prints("bro/print/"); Broker::subscribe_to_prints("bro/print/");
Broker::listen(broker_port, "127.0.0.1");
} }
global messages_to_recv = 6; global messages_to_recv = 6;
@ -37,7 +37,7 @@ event Broker::print_handler(msg: string)
return; return;
} }
Broker::print("bro/print/my_topic", fmt("pong %d", messages_sent)); Broker::send_print("bro/print/my_topic", fmt("pong %d", messages_sent));
++messages_sent; ++messages_sent;
} }
@ -64,7 +64,7 @@ event Broker::outgoing_connection_established(peer_address: string,
peer_name: string) peer_name: string)
{ {
print "Broker::outgoing_connection_established", peer_address, peer_port; print "Broker::outgoing_connection_established", peer_address, peer_port;
Broker::print("bro/print/hi", fmt("ping %d", messages_sent)); Broker::send_print("bro/print/hi", fmt("ping %d", messages_sent));
++messages_sent; ++messages_sent;
} }
@ -78,7 +78,7 @@ event Broker::print_handler(msg: string)
{ {
++messages_recv; ++messages_recv;
print "got print msg", msg; print "got print msg", msg;
Broker::print("bro/print/hi", fmt("ping %d", messages_sent)); Broker::send_print("bro/print/hi", fmt("ping %d", messages_sent));
++messages_sent; ++messages_sent;
} }

View file

@ -21,11 +21,11 @@ event Broker::outgoing_connection_established(peer_address: string,
{ {
print "Broker::outgoing_connection_established", print "Broker::outgoing_connection_established",
peer_address, peer_port, peer_name; peer_address, peer_port, peer_name;
Broker::event("bro/event/my_event", Broker::event_args(my_event, "hi", 0)); Broker::send_event("bro/event/my_event", Broker::event_args(my_event, "hi", 0));
event my_auto_event("stuff", 88); event my_auto_event("stuff", 88);
Broker::event("bro/event/my_event", Broker::event_args(my_event, "...", 1)); Broker::send_event("bro/event/my_event", Broker::event_args(my_event, "...", 1));
event my_auto_event("more stuff", 51); event my_auto_event("more stuff", 51);
Broker::event("bro/event/my_event", Broker::event_args(my_event, "bye", 2)); Broker::send_event("bro/event/my_event", Broker::event_args(my_event, "bye", 2));
} }
event Broker::outgoing_connection_broken(peer_address: string, event Broker::outgoing_connection_broken(peer_address: string,

View file

@ -18,9 +18,9 @@ event Broker::outgoing_connection_established(peer_address: string,
{ {
print "Broker::outgoing_connection_established", print "Broker::outgoing_connection_established",
peer_address, peer_port, peer_name; peer_address, peer_port, peer_name;
Broker::print("bro/print/hi", "hello"); Broker::send_print("bro/print/hi", "hello");
Broker::print("bro/print/stuff", "..."); Broker::send_print("bro/print/stuff", "...");
Broker::print("bro/print/bye", "goodbye"); Broker::send_print("bro/print/bye", "goodbye");
} }
event Broker::outgoing_connection_broken(peer_address: string, event Broker::outgoing_connection_broken(peer_address: string,

View file

@ -105,14 +105,14 @@ event NetControl::acld_add_rule(id: count, r: NetControl::Rule, ar: NetControl::
{ {
print "add_rule", id, r$entity, r$ty, ar; print "add_rule", id, r$entity, r$ty, ar;
Broker::event("bro/event/netcontroltest", Broker::event_args(NetControl::acld_rule_added, id, r, ar$command)); Broker::send_event("bro/event/netcontroltest", Broker::event_args(NetControl::acld_rule_added, id, r, ar$command));
} }
event NetControl::acld_remove_rule(id: count, r: NetControl::Rule, ar: NetControl::AclRule) event NetControl::acld_remove_rule(id: count, r: NetControl::Rule, ar: NetControl::AclRule)
{ {
print "remove_rule", id, r$entity, r$ty, ar; print "remove_rule", id, r$entity, r$ty, ar;
Broker::event("bro/event/netcontroltest", Broker::event_args(NetControl::acld_rule_removed, id, r, ar$command)); Broker::send_event("bro/event/netcontroltest", Broker::event_args(NetControl::acld_rule_removed, id, r, ar$command));
if ( r$cid == 4 ) if ( r$cid == 4 )
terminate(); terminate();

View file

@ -98,14 +98,14 @@ event NetControl::acld_add_rule(id: count, r: NetControl::Rule, ar: NetControl::
{ {
print "add_rule", id, r$entity, r$ty, ar; print "add_rule", id, r$entity, r$ty, ar;
Broker::event("bro/event/netcontroltest", Broker::event_args(NetControl::acld_rule_added, id, r, ar$command)); Broker::send_event("bro/event/netcontroltest", Broker::event_args(NetControl::acld_rule_added, id, r, ar$command));
} }
event NetControl::acld_remove_rule(id: count, r: NetControl::Rule, ar: NetControl::AclRule) event NetControl::acld_remove_rule(id: count, r: NetControl::Rule, ar: NetControl::AclRule)
{ {
print "remove_rule", id, r$entity, r$ty, ar; print "remove_rule", id, r$entity, r$ty, ar;
Broker::event("bro/event/netcontroltest", Broker::event_args(NetControl::acld_rule_removed, id, r, ar$command)); Broker::send_event("bro/event/netcontroltest", Broker::event_args(NetControl::acld_rule_removed, id, r, ar$command));
if ( r$cid == 4 ) if ( r$cid == 4 )
terminate(); terminate();

View file

@ -89,15 +89,15 @@ event NetControl::broker_add_rule(id: count, r: NetControl::Rule)
{ {
print "add_rule", id, r$entity, r$ty; print "add_rule", id, r$entity, r$ty;
Broker::event("bro/event/netcontroltest", Broker::event_args(NetControl::broker_rule_added, id, r, "")); Broker::send_event("bro/event/netcontroltest", Broker::event_args(NetControl::broker_rule_added, id, r, ""));
} }
event NetControl::broker_remove_rule(id: count, r: NetControl::Rule) event NetControl::broker_remove_rule(id: count, r: NetControl::Rule)
{ {
print "remove_rule", id, r$entity, r$ty; print "remove_rule", id, r$entity, r$ty;
Broker::event("bro/event/netcontroltest", Broker::event_args(NetControl::broker_rule_timeout, id, r, NetControl::FlowInfo())); Broker::send_event("bro/event/netcontroltest", Broker::event_args(NetControl::broker_rule_timeout, id, r, NetControl::FlowInfo()));
Broker::event("bro/event/netcontroltest", Broker::event_args(NetControl::broker_rule_removed, id, r, "")); Broker::send_event("bro/event/netcontroltest", Broker::event_args(NetControl::broker_rule_removed, id, r, ""));
if ( r$cid == 3 ) if ( r$cid == 3 )
terminate(); terminate();

View file

@ -104,8 +104,8 @@ function got_message()
event OpenFlow::broker_flow_mod(name: string, dpid: count, match: OpenFlow::ofp_match, flow_mod: OpenFlow::ofp_flow_mod) event OpenFlow::broker_flow_mod(name: string, dpid: count, match: OpenFlow::ofp_match, flow_mod: OpenFlow::ofp_flow_mod)
{ {
print "got flow_mod", dpid, match, flow_mod; print "got flow_mod", dpid, match, flow_mod;
Broker::event("bro/event/openflow", Broker::event_args(OpenFlow::flow_mod_success, name, match, flow_mod, "")); Broker::send_event("bro/event/openflow", Broker::event_args(OpenFlow::flow_mod_success, name, match, flow_mod, ""));
Broker::event("bro/event/openflow", Broker::event_args(OpenFlow::flow_mod_failure, name, match, flow_mod, "")); Broker::send_event("bro/event/openflow", Broker::event_args(OpenFlow::flow_mod_failure, name, match, flow_mod, ""));
got_message(); got_message();
} }