X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=ofproto%2Fprivate.h;h=80c59e466eb98fc0ee9f94938399edc3047272d5;hb=691ac3d8c5f892b8d423c8855d55fecf24abd1ae;hp=cadd19e85865fb8b10b5ce4d2704774e1ce6af53;hpb=abe529af477b8311a1fd68c130374bd7442003c3;p=openvswitch diff --git a/ofproto/private.h b/ofproto/private.h index cadd19e8..80c59e46 100644 --- a/ofproto/private.h +++ b/ofproto/private.h @@ -45,12 +45,12 @@ struct ofproto { char *dp_desc; /* Datapath description. */ /* Datapath. */ - struct netdev_monitor *netdev_monitor; struct hmap ports; /* Contains "struct ofport"s. */ struct shash port_by_name; - /* Flow table. */ - struct classifier cls; /* Contains "struct rule"s. */ + /* Flow tables. */ + struct classifier *tables; /* Each classifier contains "struct rule"s. */ + int n_tables; /* OpenFlow connections. */ struct connmgr *connmgr; @@ -69,6 +69,7 @@ struct ofport { struct netdev *netdev; struct ofp_phy_port opp; uint16_t ofp_port; /* OpenFlow port number. */ + unsigned int change_seq; }; /* An OpenFlow flow within a "struct ofproto". @@ -84,6 +85,7 @@ struct rule { long long int created; /* Creation time. */ uint16_t idle_timeout; /* In seconds from time of last use. */ uint16_t hard_timeout; /* In seconds from time of creation. */ + uint8_t table_id; /* Index in ofproto's 'tables' array. */ bool send_flow_removed; /* Send a flow removed message? */ union ofp_action *actions; /* OpenFlow actions. */ @@ -96,7 +98,6 @@ rule_from_cls_rule(const struct cls_rule *cls_rule) return cls_rule ? CONTAINER_OF(cls_rule, struct rule, cr) : NULL; } -struct rule *ofproto_rule_lookup(struct ofproto *, const struct flow *); void ofproto_rule_expire(struct rule *, uint8_t reason); void ofproto_rule_destroy(struct rule *); @@ -204,8 +205,30 @@ struct ofproto_class { /* ## Factory Functions ## */ /* ## ----------------- ## */ + /* Enumerates the types of all support ofproto types into 'types'. The + * caller has already initialized 'types' and other ofproto classes might + * already have added names to it. */ void (*enumerate_types)(struct sset *types); + + /* Enumerates the names of all existing datapath of the specified 'type' + * into 'names' 'all_dps'. The caller has already initialized 'names' as + * an empty sset. + * + * 'type' is one of the types enumerated by ->enumerate_types(). + * + * Returns 0 if successful, otherwise a positive errno value. + */ int (*enumerate_names)(const char *type, struct sset *names); + + /* Deletes the datapath with the specified 'type' and 'name'. The caller + * should have closed any open ofproto with this 'type' and 'name'; this + * function is allowed to fail if that is not the case. + * + * 'type' is one of the types enumerated by ->enumerate_types(). + * 'name' is one of the names enumerated by ->enumerate_names() for 'type'. + * + * Returns 0 if successful, otherwise a positive errno value. + */ int (*del)(const char *type, const char *name); /* ## --------------------------- ## */ @@ -214,17 +237,25 @@ struct ofproto_class { /* Life-cycle functions for an "ofproto" (see "Life Cycle" above). * - * ->construct() should not modify any base members of the ofproto, even - * though it may be tempting in a few cases. In particular, the client - * will initialize the ofproto's 'ports' member after construction is - * complete. An ofproto's flow table should be initially empty, so - * ->construct() should delete flows from the underlying datapath, if - * necessary, rather than populating the ofproto's 'cls'. + * ->construct() should not modify most base members of the ofproto. In + * particular, the client will initialize the ofproto's 'ports' member + * after construction is complete. + * + * ->construct() should initialize the base 'n_tables' member to the number + * of flow tables supported by the datapath (between 1 and 255, inclusive), + * initialize the base 'tables' member with space for one classifier per + * table, and initialize each classifier with classifier_init. Each flow + * table should be initially empty, so ->construct() should delete flows + * from the underlying datapath, if necessary, rather than populating the + * tables. * * Only one ofproto instance needs to be supported for any given datapath. * If a datapath is already open as part of one "ofproto", then another * attempt to "construct" the same datapath as part of another ofproto is - * allowed to fail with an error. */ + * allowed to fail with an error. + * + * ->construct() returns 0 if successful, otherwise a positive errno + * value. */ struct ofproto *(*alloc)(void); int (*construct)(struct ofproto *ofproto); void (*destruct)(struct ofproto *ofproto); @@ -238,6 +269,10 @@ struct ofproto_class { * * - Call ofproto_rule_expire() for each OpenFlow flow that has reached * its hard_timeout or idle_timeout, to expire the flow. + * + * Returns 0 if successful, otherwise a positive errno value. The ENODEV + * return value specifically means that the datapath underlying 'ofproto' + * has been destroyed (externally, e.g. by an admin running ovs-dpctl). */ int (*run)(struct ofproto *ofproto); @@ -256,6 +291,61 @@ struct ofproto_class { * than to do it one by one. */ void (*flush)(struct ofproto *ofproto); + /* Helper for the OpenFlow OFPT_FEATURES_REQUEST request. + * + * The implementation should store true in '*arp_match_ip' if the switch + * supports matching IP addresses inside ARP requests and replies, false + * otherwise. + * + * The implementation should store in '*actions' a bitmap of the supported + * OpenFlow actions: the bit with value (1 << n) should be set to 1 if the + * implementation supports the action with value 'n', and to 0 otherwise. + * For example, if the implementation supports the OFPAT_OUTPUT and + * OFPAT_ENQUEUE actions, but no others, it would set '*actions' to (1 << + * OFPAT_OUTPUT) | (1 << OFPAT_ENQUEUE). Vendor actions are not included + * in '*actions'. */ + void (*get_features)(struct ofproto *ofproto, + bool *arp_match_ip, uint32_t *actions); + + /* Helper for the OpenFlow OFPST_TABLE statistics request. + * + * The 'ots' array contains 'ofproto->n_tables' elements. Each element is + * initialized as: + * + * - 'table_id' to the array index. + * + * - 'name' to "table#" where # is the table ID. + * + * - 'wildcards' to OFPFW_ALL. + * + * - 'max_entries' to 1,000,000. + * + * - 'active_count' to the classifier_count() for the table. + * + * - 'lookup_count' and 'matched_count' to 0. + * + * The implementation should update any members in each element for which + * it has better values: + * + * - 'name' to a more meaningful name. + * + * - 'wildcards' to the set of wildcards actually supported by the table + * (if it doesn't support all OpenFlow wildcards). + * + * - 'max_entries' to the maximum number of flows actually supported by + * the hardware. + * + * - 'lookup_count' to the number of packets looked up in this flow table + * so far. + * + * - 'matched_count' to the number of packets looked up in this flow + * table so far that matched one of the flow entries. + * + * Keep in mind that all of the members of struct ofp_table_stats are in + * network byte order. + */ + void (*get_tables)(struct ofproto *ofproto, struct ofp_table_stats *ots); + /* ## ---------------- ## */ /* ## ofport Functions ## */ /* ## ---------------- ## */ @@ -284,6 +374,9 @@ struct ofproto_class { * implementation's ports, in the same way as at ofproto * initialization, and construct and destruct ofports to reflect all of * the changes. + * + * ->port_construct() returns 0 if successful, otherwise a positive errno + * value. */ struct ofport *(*port_alloc)(void); int (*port_construct)(struct ofport *ofport); @@ -316,12 +409,22 @@ struct ofproto_class { int (*port_query_by_name)(const struct ofproto *ofproto, const char *devname, struct ofproto_port *port); - /* Attempts to add 'netdev' as a port on 'ofproto'. If successful, sets - * '*ofp_portp' to the new port's port number. */ + /* Attempts to add 'netdev' as a port on 'ofproto'. Returns 0 if + * successful, otherwise a positive errno value. If successful, sets + * '*ofp_portp' to the new port's port number. + * + * It doesn't matter whether the new port will be returned by a later call + * to ->port_poll(); the implementation may do whatever is more + * convenient. */ int (*port_add)(struct ofproto *ofproto, struct netdev *netdev, uint16_t *ofp_portp); - /* Deletes port number 'ofp_port' from the datapath for 'ofproto'. */ + /* Deletes port number 'ofp_port' from the datapath for 'ofproto'. Returns + * 0 if successful, otherwise a positive errno value. + * + * It doesn't matter whether the new port will be returned by a later call + * to ->port_poll(); the implementation may do whatever is more + * convenient. */ int (*port_del)(struct ofproto *ofproto, uint16_t ofp_port); /* Attempts to begin dumping the ports in 'ofproto'. On success, returns 0 @@ -371,39 +474,183 @@ struct ofproto_class { * * If the set of ports in 'ofproto' has not changed, returns EAGAIN. May * also return other positive errno values to indicate that something has - * gone wrong. */ + * gone wrong. + * + * If the set of ports in a datapath is fixed, or if the only way that the + * set of ports in a datapath can change is through ->port_add() and + * ->port_del(), then this function may be a null pointer. + */ int (*port_poll)(const struct ofproto *ofproto, char **devnamep); - /* Arranges for the poll loop to wake up when 'port_poll' will return a - * value other than EAGAIN. */ + /* Arranges for the poll loop to wake up when ->port_poll() will return a + * value other than EAGAIN. + * + * If the set of ports in a datapath is fixed, or if the only way that the + * set of ports in a datapath can change is through ->port_add() and + * ->port_del(), or if the poll loop will always wake up anyway when + * ->port_poll() will return a value other than EAGAIN, then this function + * may be a null pointer. + */ void (*port_poll_wait)(const struct ofproto *ofproto); + /* Checks the status of LACP negotiation for 'port'. Returns 1 if LACP + * partner information for 'port' is up-to-date, 0 if LACP partner + * information is not current (generally indicating a connectivity + * problem), or -1 if LACP is not enabled on 'port'. + * + * This function may be a null pointer if the ofproto implementation does + * not support LACP. */ int (*port_is_lacp_current)(const struct ofport *port); +/* ## ----------------------- ## */ +/* ## OpenFlow Rule Functions ## */ +/* ## ----------------------- ## */ + + /* Chooses an appropriate table for 'cls_rule' within 'ofproto'. On + * success, stores the table ID into '*table_idp' and returns 0. On + * failure, returns an OpenFlow error code (as returned by ofp_mkerr()). + * + * The choice of table should be a function of 'cls_rule' and 'ofproto''s + * datapath capabilities. It should not depend on the flows already in + * 'ofproto''s flow tables. Failure implies that an OpenFlow rule with + * 'cls_rule' as its matching condition can never be inserted into + * 'ofproto', even starting from an empty flow table. + * + * If multiple tables are candidates for inserting the flow, the function + * should choose one arbitrarily (but deterministically). + * + * This function will never be called for an ofproto that has only one + * table, so it may be NULL in that case. */ + int (*rule_choose_table)(const struct ofproto *ofproto, + const struct cls_rule *cls_rule, + uint8_t *table_idp); + + /* Life-cycle functions for a "struct rule" (see "Life Cycle" above). + * + * ->rule_construct() should first check whether the rule is acceptable: + * + * - Validate that the matching rule in 'rule->cr' is supported by the + * datapath. If not, then return an OpenFlow error code (as returned + * by ofp_mkerr()). + * + * For example, if the datapath does not support registers, then it + * should return an error if 'rule->cr' does not wildcard all + * registers. + * + * - Validate that 'rule->actions' and 'rule->n_actions' are well-formed + * OpenFlow actions that can be correctly implemented by the datapath. + * If not, then return an OpenFlow error code (as returned by + * ofp_mkerr()). + * + * The validate_actions() function (in ofp-util.c) can be useful as a + * model for action validation, but it accepts all of the OpenFlow + * actions that OVS understands. If your ofproto implementation only + * implements a subset of those, then you should implement your own + * action validation. + * + * If the rule is acceptable, then ->rule_construct() should modify the + * flow table: + * + * - If there was already a rule with exactly the same matching criteria + * and priority in the classifier, then it should destroy it (with + * ofproto_rule_destroy()). + * + * To the greatest extent possible, the old rule should be destroyed + * only if inserting the new rule succeeds; that is, ->rule_construct() + * should be transactional. + * + * The function classifier_find_rule_exactly() can locate such a rule. + * + * - Insert the new rule into the ofproto's 'cls' classifier, and into + * the datapath flow table. + * + * The function classifier_insert() inserts a rule into the classifier. + * + * Other than inserting 'rule->cr' into the classifier, ->rule_construct() + * should not modify any base members of struct rule. + * + * ->rule_destruct() should remove 'rule' from the ofproto's 'cls' + * classifier (e.g. with classifier_remove()) and from the datapath flow + * table. */ struct rule *(*rule_alloc)(void); int (*rule_construct)(struct rule *rule); void (*rule_destruct)(struct rule *rule); void (*rule_dealloc)(struct rule *rule); - void (*rule_remove)(struct rule *rule); - + /* Obtains statistics for 'rule', storing the number of packets that have + * matched it in '*packet_count' and the number of bytes in those packets + * in '*byte_count'. */ void (*rule_get_stats)(struct rule *rule, uint64_t *packet_count, uint64_t *byte_count); - void (*rule_execute)(struct rule *rule, struct flow *flow, - struct ofpbuf *packet); - + /* Applies the actions in 'rule' to 'packet'. (This implements sending + * buffered packets for OpenFlow OFPT_FLOW_MOD commands.) + * + * Takes ownership of 'packet' (so it should eventually free it, with + * ofpbuf_delete()). + * + * 'flow' reflects the flow information for 'packet'. All of the + * information in 'flow' is extracted from 'packet', except for + * flow->tun_id and flow->in_port, which are assigned the correct values + * for the incoming packet. The register values are zeroed. + * + * The statistics for 'packet' should be included in 'rule'. + * + * Returns 0 if successful, otherwise an OpenFlow error code (as returned + * by ofp_mkerr()). */ + int (*rule_execute)(struct rule *rule, struct flow *flow, + struct ofpbuf *packet); + + /* Validates that the 'n' elements in 'actions' are well-formed OpenFlow + * actions that can be correctly implemented by the datapath. If not, then + * return an OpenFlow error code (as returned by ofp_mkerr()). If so, + * then update the datapath to implement the new actions and return 0. + * + * When this function runs, 'rule' still has its original actions. If this + * function returns 0, then the caller will update 'rule' with the new + * actions and free the old ones. */ int (*rule_modify_actions)(struct rule *rule, const union ofp_action *actions, size_t n); + /* These functions implement the OpenFlow IP fragment handling policy. By + * default ('drop_frags' == false), an OpenFlow switch should treat IP + * fragments the same way as other packets (although TCP and UDP port + * numbers cannot be determined). With 'drop_frags' == true, the switch + * should drop all IP fragments without passing them through the flow + * table. */ bool (*get_drop_frags)(struct ofproto *ofproto); void (*set_drop_frags)(struct ofproto *ofproto, bool drop_frags); + /* Implements the OpenFlow OFPT_PACKET_OUT command. The datapath should + * execute the 'n_actions' in the 'actions' array on 'packet'. + * + * The caller retains ownership of 'packet', so ->packet_out() should not + * modify or free it. + * + * This function must validate that the 'n_actions' elements in 'actions' + * are well-formed OpenFlow actions that can be correctly implemented by + * the datapath. If not, then it should return an OpenFlow error code (as + * returned by ofp_mkerr()). + * + * 'flow' reflects the flow information for 'packet'. All of the + * information in 'flow' is extracted from 'packet', except for + * flow->in_port, which is taken from the OFPT_PACKET_OUT message. + * flow->tun_id and its register values are zeroed. + * + * 'packet' is not matched against the OpenFlow flow table, so its + * statistics should not be included in OpenFlow flow statistics. + * + * Returns 0 if successful, otherwise an OpenFlow error code (as returned + * by ofp_mkerr()). */ int (*packet_out)(struct ofproto *ofproto, struct ofpbuf *packet, const struct flow *flow, const union ofp_action *actions, size_t n_actions); - + +/* ## ------------------------- ## */ +/* ## OFPP_NORMAL configuration ## */ +/* ## ------------------------- ## */ + /* Configures NetFlow on 'ofproto' according to the options in * 'netflow_options', or turns off NetFlow if 'netflow_options' is NULL. * @@ -425,25 +672,22 @@ struct ofproto_class { /* Configures connectivity fault management on 'ofport'. * - * If 'cfm' is nonnull, takes basic configuration from the configuration - * members in 'cfm', and the set of remote maintenance points from the - * 'n_remote_mps' elements in 'remote_mps'. Ignores the statistics members - * of 'cfm'. + * If 'cfm_settings' is nonnull, configures CFM according to its members. * - * If 'cfm' is null, removes any connectivity fault management + * If 'cfm_settings' is null, removes any connectivity fault management * configuration from 'ofport'. * * EOPNOTSUPP as a return value indicates that this ofproto_class does not * support CFM, as does a null pointer. */ - int (*set_cfm)(struct ofport *ofport, const struct cfm *cfm, - const uint16_t *remote_mps, size_t n_remote_mps); + int (*set_cfm)(struct ofport *ofport, const struct cfm_settings *s); - /* Stores the connectivity fault management object associated with 'ofport' - * in '*cfmp'. Stores a null pointer in '*cfmp' if CFM is not configured - * on 'ofport'. The caller must not modify or destroy the returned object. + /* Checks the fault status of CFM configured on 'ofport'. Returns 1 if CFM + * is faulted (generally indicating a connectivity problem), 0 if CFM is + * not faulted, or -1 if CFM is not enabled on 'port' * - * This function may be NULL if this ofproto_class does not support CFM. */ - int (*get_cfm)(struct ofport *ofport, const struct cfm **cfmp); + * This function may be a null pointer if the ofproto implementation does + * not support CFM. */ + int (*get_cfm_fault)(const struct ofport *ofport); /* If 's' is nonnull, this function registers a "bundle" associated with * client data pointer 'aux' in 'ofproto'. A bundle is the same concept as