ofproto->max_ports = OFPP_MAX;
ofproto->tables = NULL;
ofproto->n_tables = 0;
+ list_init(&ofproto->expirable);
ofproto->connmgr = connmgr_create(ofproto, datapath_name, datapath_name);
ofproto->state = S_OPENFLOW;
list_init(&ofproto->pending);
uint16_t flags = ntohs(osc->flags);
if (ofconn_get_type(ofconn) != OFCONN_PRIMARY
- || ofconn_get_role(ofconn) != NX_ROLE_SLAVE) {
+ || ofconn_get_role(ofconn) != OFPCR12_ROLE_SLAVE) {
enum ofp_config_flags cur = ofproto->frag_handling;
enum ofp_config_flags next = flags & OFPC_FRAG_MASK;
reject_slave_controller(struct ofconn *ofconn)
{
if (ofconn_get_type(ofconn) == OFCONN_PRIMARY
- && ofconn_get_role(ofconn) == NX_ROLE_SLAVE) {
+ && ofconn_get_role(ofconn) == OFPCR12_ROLE_SLAVE) {
return OFPERR_OFPBRC_EPERM;
} else {
return 0;
ofproto->ofproto_class->get_netflow_ids(ofproto, engine_type, engine_id);
}
-/* Checks the fault status of CFM for 'ofp_port' within 'ofproto'. Returns a
- * bitmask of 'cfm_fault_reason's to indicate a CFM fault (generally
- * indicating a connectivity problem). Returns zero if CFM is not faulted,
- * and -1 if CFM is not enabled on 'ofp_port'. */
-int
-ofproto_port_get_cfm_fault(const struct ofproto *ofproto, uint16_t ofp_port)
-{
- struct ofport *ofport = ofproto_get_port(ofproto, ofp_port);
- return (ofport && ofproto->ofproto_class->get_cfm_fault
- ? ofproto->ofproto_class->get_cfm_fault(ofport)
- : -1);
-}
-
-/* Checks the operational status reported by the remote CFM endpoint of
- * 'ofp_port' Returns 1 if operationally up, 0 if operationally down, and -1
- * if CFM is not enabled on 'ofp_port' or does not support operational status.
- */
-int
-ofproto_port_get_cfm_opup(const struct ofproto *ofproto, uint16_t ofp_port)
-{
- struct ofport *ofport = ofproto_get_port(ofproto, ofp_port);
- return (ofport && ofproto->ofproto_class->get_cfm_opup
- ? ofproto->ofproto_class->get_cfm_opup(ofport)
- : -1);
-}
-
-/* Gets the MPIDs of the remote maintenance points broadcasting to 'ofp_port'
- * within 'ofproto'. Populates 'rmps' with an array of MPIDs owned by
- * 'ofproto', and 'n_rmps' with the number of MPIDs in 'rmps'. Returns a
- * number less than 0 if CFM is not enabled on 'ofp_port'. */
-int
-ofproto_port_get_cfm_remote_mpids(const struct ofproto *ofproto,
- uint16_t ofp_port, const uint64_t **rmps,
- size_t *n_rmps)
-{
- struct ofport *ofport = ofproto_get_port(ofproto, ofp_port);
-
- *rmps = NULL;
- *n_rmps = 0;
- return (ofport && ofproto->ofproto_class->get_cfm_remote_mpids
- ? ofproto->ofproto_class->get_cfm_remote_mpids(ofport, rmps,
- n_rmps)
- : -1);
-}
-
-/* Checks the health of the CFM for 'ofp_port' within 'ofproto'. Returns an
- * integer value between 0 and 100 to indicate the health of the port as a
- * percentage which is the average of cfm health of all the remote_mpids or
- * returns -1 if CFM is not enabled on 'ofport'. */
-int
-ofproto_port_get_cfm_health(const struct ofproto *ofproto, uint16_t ofp_port)
+/* Checks the status of CFM configured on 'ofp_port' within 'ofproto'. Returns
+ * true if the port's CFM status was successfully stored into '*status'.
+ * Returns false if the port did not have CFM configured, in which case
+ * '*status' is indeterminate.
+ *
+ * The caller must provide and owns '*status', but it does not own and must not
+ * modify or free the array returned in 'status->rmps'. */
+bool
+ofproto_port_get_cfm_status(const struct ofproto *ofproto, uint16_t ofp_port,
+ struct ofproto_cfm_status *status)
{
struct ofport *ofport = ofproto_get_port(ofproto, ofp_port);
- return (ofport && ofproto->ofproto_class->get_cfm_health
- ? ofproto->ofproto_class->get_cfm_health(ofport)
- : -1);
+ return (ofport
+ && ofproto->ofproto_class->get_cfm_status
+ && ofproto->ofproto_class->get_cfm_status(ofport, status));
}
static enum ofperr
rule->ofpacts_len = fm->ofpacts_len;
rule->evictable = true;
rule->eviction_group = NULL;
+ list_init(&rule->expirable);
rule->monitor_flags = 0;
rule->add_seqno = 0;
rule->modify_seqno = 0;
new_cookie = (fm->new_cookie != htonll(UINT64_MAX)
? fm->new_cookie
: rule->flow_cookie);
- if (!actions_changed && new_cookie == rule->flow_cookie) {
- /* No change at all. */
- continue;
- }
op = ofoperation_create(group, rule, OFOPERATION_MODIFY, 0);
rule->flow_cookie = new_cookie;
static enum ofperr
handle_role_request(struct ofconn *ofconn, const struct ofp_header *oh)
{
- struct ofputil_role_request rr;
+ struct ofputil_role_request request;
+ struct ofputil_role_request reply;
struct ofpbuf *buf;
- uint32_t role;
enum ofperr error;
- error = ofputil_decode_role_message(oh, &rr);
+ error = ofputil_decode_role_message(oh, &request);
if (error) {
return error;
}
- if (rr.request_current_role_only) {
- role = ofconn_get_role(ofconn); /* NX_ROLE_* */
- goto reply;
- }
-
- role = rr.role;
-
- if (ofconn_get_role(ofconn) != role
- && ofconn_has_pending_opgroups(ofconn)) {
- return OFPROTO_POSTPONE;
- }
+ if (request.role != OFPCR12_ROLE_NOCHANGE) {
+ if (ofconn_get_role(ofconn) != request.role
+ && ofconn_has_pending_opgroups(ofconn)) {
+ return OFPROTO_POSTPONE;
+ }
- if (rr.have_generation_id) {
- if (!ofconn_set_master_election_id(ofconn, rr.generation_id)) {
- return OFPERR_OFPRRFC_STALE;
+ if (request.have_generation_id
+ && !ofconn_set_master_election_id(ofconn, request.generation_id)) {
+ return OFPERR_OFPRRFC_STALE;
}
- }
- ofconn_set_role(ofconn, role);
+ ofconn_set_role(ofconn, request.role);
+ }
-reply:
- buf = ofputil_encode_role_reply(oh, role);
+ reply.role = ofconn_get_role(ofconn);
+ reply.have_generation_id = ofconn_get_master_election_id(
+ ofconn, &reply.generation_id);
+ buf = ofputil_encode_role_reply(oh, &reply);
ofconn_send_reply(ofconn, buf);
return 0;
LIST_FOR_EACH_SAFE (op, next_op, group_node, &group->ops) {
struct rule *rule = op->rule;
- if (!op->error && !ofproto_rule_is_hidden(rule)) {
+ /* We generally want to report the change to active OpenFlow flow
+ monitors (e.g. NXST_FLOW_MONITOR). There are three exceptions:
+
+ - The operation failed.
+
+ - The affected rule is not visible to controllers.
+
+ - The operation's only effect was to update rule->modified. */
+ if (!(op->error
+ || ofproto_rule_is_hidden(rule)
+ || (op->type == OFOPERATION_MODIFY
+ && op->ofpacts
+ && rule->flow_cookie == op->flow_cookie))) {
/* Check that we can just cast from ofoperation_type to
* nx_flow_update_event. */
BUILD_ASSERT_DECL((enum nx_flow_update_event) OFOPERATION_ADD
classifier_remove(&table->cls, &rule->cr);
eviction_group_remove_rule(rule);
+ if (!list_is_empty(&rule->expirable)) {
+ list_remove(&rule->expirable);
+ }
}
/* Inserts 'rule' into its oftable. Removes any existing rule from 'rule''s
struct ofproto *ofproto = rule->ofproto;
struct oftable *table = &ofproto->tables[rule->table_id];
struct rule *victim;
+ bool may_expire = rule->hard_timeout || rule->idle_timeout;
+
+ if (may_expire) {
+ list_insert(&ofproto->expirable, &rule->expirable);
+ }
victim = rule_from_cls_rule(classifier_replace(&table->cls, &rule->cr));
if (victim) {
+ if (!list_is_empty(&victim->expirable)) {
+ list_remove(&victim->expirable);
+ }
eviction_group_remove_rule(victim);
}
eviction_group_add_rule(rule);