2 * Copyright (c) 2010, 2011 Nicira Networks.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include "ofp-parse.h"
25 #include "byte-order.h"
26 #include "dynamic-string.h"
28 #include "multipath.h"
32 #include "openflow/openflow.h"
34 #include "socket-util.h"
38 VLOG_DEFINE_THIS_MODULE(ofp_parse);
41 str_to_u32(const char *str)
47 ovs_fatal(0, "missing required numeric argument");
51 value = strtoul(str, &tail, 0);
52 if (errno == EINVAL || errno == ERANGE || *tail) {
53 ovs_fatal(0, "invalid numeric format %s", str);
59 str_to_u64(const char *str)
65 ovs_fatal(0, "missing required numeric argument");
69 value = strtoull(str, &tail, 0);
70 if (errno == EINVAL || errno == ERANGE || *tail) {
71 ovs_fatal(0, "invalid numeric format %s", str);
77 str_to_mac(const char *str, uint8_t mac[6])
79 if (sscanf(str, ETH_ADDR_SCAN_FMT, ETH_ADDR_SCAN_ARGS(mac))
80 != ETH_ADDR_SCAN_COUNT) {
81 ovs_fatal(0, "invalid mac address %s", str);
86 str_to_ip(const char *str_, ovs_be32 *ip, ovs_be32 *maskp)
88 char *str = xstrdup(str_);
89 char *save_ptr = NULL;
90 const char *name, *netmask;
91 struct in_addr in_addr;
95 name = strtok_r(str, "/", &save_ptr);
96 retval = name ? lookup_ip(name, &in_addr) : EINVAL;
98 ovs_fatal(0, "%s: could not convert to IP address", str);
100 *ip = in_addr.s_addr;
102 netmask = strtok_r(NULL, "/", &save_ptr);
105 if (sscanf(netmask, "%"SCNu8".%"SCNu8".%"SCNu8".%"SCNu8,
106 &o[0], &o[1], &o[2], &o[3]) == 4) {
107 mask = htonl((o[0] << 24) | (o[1] << 16) | (o[2] << 8) | o[3]);
109 int prefix = atoi(netmask);
110 if (prefix <= 0 || prefix > 32) {
111 ovs_fatal(0, "%s: network prefix bits not between 1 and 32",
113 } else if (prefix == 32) {
114 mask = htonl(UINT32_MAX);
116 mask = htonl(((1u << prefix) - 1) << (32 - prefix));
120 mask = htonl(UINT32_MAX);
127 if (mask != htonl(UINT32_MAX)) {
128 ovs_fatal(0, "%s: netmask not allowed here", str_);
136 str_to_tun_id(const char *str, ovs_be64 *tun_idp, ovs_be64 *maskp)
138 uint64_t tun_id, mask;
142 tun_id = strtoull(str, &tail, 0);
143 if (errno || (*tail != '\0' && *tail != '/')) {
148 mask = strtoull(tail + 1, &tail, 0);
149 if (errno || *tail != '\0') {
156 *tun_idp = htonll(tun_id);
157 *maskp = htonll(mask);
161 ovs_fatal(0, "%s: bad syntax for tunnel id", str);
165 str_to_ipv6(const char *str_, struct in6_addr *addrp, struct in6_addr *maskp)
167 char *str = xstrdup(str_);
168 char *save_ptr = NULL;
169 const char *name, *netmask;
170 struct in6_addr addr, mask;
173 name = strtok_r(str, "/", &save_ptr);
174 retval = name ? lookup_ipv6(name, &addr) : EINVAL;
176 ovs_fatal(0, "%s: could not convert to IPv6 address", str);
179 netmask = strtok_r(NULL, "/", &save_ptr);
181 int prefix = atoi(netmask);
182 if (prefix <= 0 || prefix > 128) {
183 ovs_fatal(0, "%s: network prefix bits not between 1 and 128",
186 mask = ipv6_create_mask(prefix);
189 mask = in6addr_exact;
191 *addrp = ipv6_addr_bitand(&addr, &mask);
196 if (!ipv6_mask_is_exact(&mask)) {
197 ovs_fatal(0, "%s: netmask not allowed here", str_);
205 put_action(struct ofpbuf *b, size_t size, uint16_t type)
207 struct ofp_action_header *ah = ofpbuf_put_zeros(b, size);
208 ah->type = htons(type);
209 ah->len = htons(size);
213 static struct ofp_action_output *
214 put_output_action(struct ofpbuf *b, uint16_t port)
216 struct ofp_action_output *oao = put_action(b, sizeof *oao, OFPAT_OUTPUT);
217 oao->port = htons(port);
222 put_enqueue_action(struct ofpbuf *b, uint16_t port, uint32_t queue)
224 struct ofp_action_enqueue *oae = put_action(b, sizeof *oae, OFPAT_ENQUEUE);
225 oae->port = htons(port);
226 oae->queue_id = htonl(queue);
230 put_dl_addr_action(struct ofpbuf *b, uint16_t type, const char *addr)
232 struct ofp_action_dl_addr *oada = put_action(b, sizeof *oada, type);
233 str_to_mac(addr, oada->dl_addr);
238 parse_port_name(const char *name, uint16_t *port)
244 static const struct pair pairs[] = {
245 #define DEF_PAIR(NAME) {#NAME, OFPP_##NAME}
251 DEF_PAIR(CONTROLLER),
256 static const int n_pairs = ARRAY_SIZE(pairs);
259 for (i = 0; i < n_pairs; i++) {
260 if (!strcasecmp(name, pairs[i].name)) {
261 *port = pairs[i].value;
269 str_to_action(char *str, struct ofpbuf *b)
278 char empty_string[] = "";
283 pos += strspn(pos, ", \t\r\n");
289 ovs_fatal(0, "Drop actions must not be followed by other actions");
293 actlen = strcspn(pos, ":(, \t\r\n");
294 if (act[actlen] == ':') {
295 /* The argument can be separated by a colon. */
298 arg = act + actlen + 1;
299 arglen = strcspn(arg, ", \t\r\n");
300 pos = arg + arglen + (arg[arglen] != '\0');
302 } else if (act[actlen] == '(') {
303 /* The argument can be surrounded by balanced parentheses. The
304 * outermost set of parentheses is removed. */
308 arg = act + actlen + 1;
309 for (arglen = 0; level > 0; arglen++) {
310 switch (arg[arglen]) {
312 ovs_fatal(0, "unbalanced parentheses in argument to %s "
324 arg[arglen - 1] = '\0';
327 /* There might be no argument at all. */
329 pos = act + actlen + (act[actlen] != '\0');
333 if (!strcasecmp(act, "mod_vlan_vid")) {
334 struct ofp_action_vlan_vid *va;
335 va = put_action(b, sizeof *va, OFPAT_SET_VLAN_VID);
336 va->vlan_vid = htons(str_to_u32(arg));
337 } else if (!strcasecmp(act, "mod_vlan_pcp")) {
338 struct ofp_action_vlan_pcp *va;
339 va = put_action(b, sizeof *va, OFPAT_SET_VLAN_PCP);
340 va->vlan_pcp = str_to_u32(arg);
341 } else if (!strcasecmp(act, "strip_vlan")) {
342 struct ofp_action_header *ah;
343 ah = put_action(b, sizeof *ah, OFPAT_STRIP_VLAN);
344 ah->type = htons(OFPAT_STRIP_VLAN);
345 } else if (!strcasecmp(act, "mod_dl_src")) {
346 put_dl_addr_action(b, OFPAT_SET_DL_SRC, arg);
347 } else if (!strcasecmp(act, "mod_dl_dst")) {
348 put_dl_addr_action(b, OFPAT_SET_DL_DST, arg);
349 } else if (!strcasecmp(act, "mod_nw_src")) {
350 struct ofp_action_nw_addr *na;
351 na = put_action(b, sizeof *na, OFPAT_SET_NW_SRC);
352 str_to_ip(arg, &na->nw_addr, NULL);
353 } else if (!strcasecmp(act, "mod_nw_dst")) {
354 struct ofp_action_nw_addr *na;
355 na = put_action(b, sizeof *na, OFPAT_SET_NW_DST);
356 str_to_ip(arg, &na->nw_addr, NULL);
357 } else if (!strcasecmp(act, "mod_tp_src")) {
358 struct ofp_action_tp_port *ta;
359 ta = put_action(b, sizeof *ta, OFPAT_SET_TP_SRC);
360 ta->tp_port = htons(str_to_u32(arg));
361 } else if (!strcasecmp(act, "mod_tp_dst")) {
362 struct ofp_action_tp_port *ta;
363 ta = put_action(b, sizeof *ta, OFPAT_SET_TP_DST);
364 ta->tp_port = htons(str_to_u32(arg));
365 } else if (!strcasecmp(act, "mod_nw_tos")) {
366 struct ofp_action_nw_tos *nt;
367 nt = put_action(b, sizeof *nt, OFPAT_SET_NW_TOS);
368 nt->nw_tos = str_to_u32(arg);
369 } else if (!strcasecmp(act, "resubmit")) {
370 struct nx_action_resubmit *nar;
371 nar = put_action(b, sizeof *nar, OFPAT_VENDOR);
372 nar->vendor = htonl(NX_VENDOR_ID);
373 nar->subtype = htons(NXAST_RESUBMIT);
374 nar->in_port = htons(str_to_u32(arg));
375 } else if (!strcasecmp(act, "set_tunnel")
376 || !strcasecmp(act, "set_tunnel64")) {
377 uint64_t tun_id = str_to_u64(arg);
378 if (!strcasecmp(act, "set_tunnel64") || tun_id > UINT32_MAX) {
379 struct nx_action_set_tunnel64 *nast64;
380 nast64 = put_action(b, sizeof *nast64, OFPAT_VENDOR);
381 nast64->vendor = htonl(NX_VENDOR_ID);
382 nast64->subtype = htons(NXAST_SET_TUNNEL64);
383 nast64->tun_id = htonll(tun_id);
385 struct nx_action_set_tunnel *nast;
386 nast = put_action(b, sizeof *nast, OFPAT_VENDOR);
387 nast->vendor = htonl(NX_VENDOR_ID);
388 nast->subtype = htons(NXAST_SET_TUNNEL);
389 nast->tun_id = htonl(tun_id);
391 } else if (!strcasecmp(act, "drop_spoofed_arp")) {
392 struct nx_action_header *nah;
393 nah = put_action(b, sizeof *nah, OFPAT_VENDOR);
394 nah->vendor = htonl(NX_VENDOR_ID);
395 nah->subtype = htons(NXAST_DROP_SPOOFED_ARP);
396 } else if (!strcasecmp(act, "set_queue")) {
397 struct nx_action_set_queue *nasq;
398 nasq = put_action(b, sizeof *nasq, OFPAT_VENDOR);
399 nasq->vendor = htonl(NX_VENDOR_ID);
400 nasq->subtype = htons(NXAST_SET_QUEUE);
401 nasq->queue_id = htonl(str_to_u32(arg));
402 } else if (!strcasecmp(act, "pop_queue")) {
403 struct nx_action_header *nah;
404 nah = put_action(b, sizeof *nah, OFPAT_VENDOR);
405 nah->vendor = htonl(NX_VENDOR_ID);
406 nah->subtype = htons(NXAST_POP_QUEUE);
407 } else if (!strcasecmp(act, "note")) {
408 size_t start_ofs = b->size;
409 struct nx_action_note *nan;
413 nan = put_action(b, sizeof *nan, OFPAT_VENDOR);
414 nan->vendor = htonl(NX_VENDOR_ID);
415 nan->subtype = htons(NXAST_NOTE);
417 b->size -= sizeof nan->note;
418 while (*arg != '\0') {
429 byte = hexits_value(arg, 2, &ok);
431 ovs_fatal(0, "bad hex digit in `note' argument");
433 ofpbuf_put(b, &byte, 1);
438 len = b->size - start_ofs;
439 remainder = len % OFP_ACTION_ALIGN;
441 ofpbuf_put_zeros(b, OFP_ACTION_ALIGN - remainder);
443 nan = (struct nx_action_note *)((char *)b->data + start_ofs);
444 nan->len = htons(b->size - start_ofs);
445 } else if (!strcasecmp(act, "move")) {
446 struct nx_action_reg_move *move;
447 move = ofpbuf_put_uninit(b, sizeof *move);
448 nxm_parse_reg_move(move, arg);
449 } else if (!strcasecmp(act, "load")) {
450 struct nx_action_reg_load *load;
451 load = ofpbuf_put_uninit(b, sizeof *load);
452 nxm_parse_reg_load(load, arg);
453 } else if (!strcasecmp(act, "multipath")) {
454 struct nx_action_multipath *nam;
455 nam = ofpbuf_put_uninit(b, sizeof *nam);
456 multipath_parse(nam, arg);
457 } else if (!strcasecmp(act, "output")) {
458 put_output_action(b, str_to_u32(arg));
459 } else if (!strcasecmp(act, "enqueue")) {
461 char *port_s = strtok_r(arg, ":q", &sp);
462 char *queue = strtok_r(NULL, "", &sp);
463 if (port_s == NULL || queue == NULL) {
464 ovs_fatal(0, "\"enqueue\" syntax is \"enqueue:PORT:QUEUE\"");
466 put_enqueue_action(b, str_to_u32(port_s), str_to_u32(queue));
467 } else if (!strcasecmp(act, "drop")) {
468 /* A drop action in OpenFlow occurs by just not setting
472 ovs_fatal(0, "Drop actions must not be preceded by other "
475 } else if (!strcasecmp(act, "CONTROLLER")) {
476 struct ofp_action_output *oao;
477 oao = put_output_action(b, OFPP_CONTROLLER);
479 /* Unless a numeric argument is specified, we send the whole
480 * packet to the controller. */
481 if (arg[0] && (strspn(arg, "0123456789") == strlen(arg))) {
482 oao->max_len = htons(str_to_u32(arg));
484 oao->max_len = htons(UINT16_MAX);
486 } else if (parse_port_name(act, &port)) {
487 put_output_action(b, port);
488 } else if (strspn(act, "0123456789") == strlen(act)) {
489 put_output_action(b, str_to_u32(act));
491 ovs_fatal(0, "Unknown action: %s", act);
504 parse_protocol(const char *name, const struct protocol **p_out)
506 static const struct protocol protocols[] = {
507 { "ip", ETH_TYPE_IP, 0 },
508 { "arp", ETH_TYPE_ARP, 0 },
509 { "icmp", ETH_TYPE_IP, IPPROTO_ICMP },
510 { "tcp", ETH_TYPE_IP, IPPROTO_TCP },
511 { "udp", ETH_TYPE_IP, IPPROTO_UDP },
512 { "ipv6", ETH_TYPE_IPV6, 0 },
513 { "ip6", ETH_TYPE_IPV6, 0 },
514 { "icmp6", ETH_TYPE_IPV6, IPPROTO_ICMPV6 },
515 { "tcp6", ETH_TYPE_IPV6, IPPROTO_TCP },
516 { "udp6", ETH_TYPE_IPV6, IPPROTO_UDP },
518 const struct protocol *p;
520 for (p = protocols; p < &protocols[ARRAY_SIZE(protocols)]; p++) {
521 if (!strcmp(p->name, name)) {
531 FIELD(F_TUN_ID, "tun_id", 0) \
532 FIELD(F_IN_PORT, "in_port", FWW_IN_PORT) \
533 FIELD(F_DL_VLAN, "dl_vlan", 0) \
534 FIELD(F_DL_VLAN_PCP, "dl_vlan_pcp", 0) \
535 FIELD(F_DL_SRC, "dl_src", FWW_DL_SRC) \
536 FIELD(F_DL_DST, "dl_dst", FWW_DL_DST) \
537 FIELD(F_DL_TYPE, "dl_type", FWW_DL_TYPE) \
538 FIELD(F_NW_SRC, "nw_src", 0) \
539 FIELD(F_NW_DST, "nw_dst", 0) \
540 FIELD(F_NW_PROTO, "nw_proto", FWW_NW_PROTO) \
541 FIELD(F_NW_TOS, "nw_tos", FWW_NW_TOS) \
542 FIELD(F_TP_SRC, "tp_src", FWW_TP_SRC) \
543 FIELD(F_TP_DST, "tp_dst", FWW_TP_DST) \
544 FIELD(F_ICMP_TYPE, "icmp_type", FWW_TP_SRC) \
545 FIELD(F_ICMP_CODE, "icmp_code", FWW_TP_DST) \
546 FIELD(F_ARP_SHA, "arp_sha", FWW_ARP_SHA) \
547 FIELD(F_ARP_THA, "arp_tha", FWW_ARP_THA) \
548 FIELD(F_IPV6_SRC, "ipv6_src", 0) \
549 FIELD(F_IPV6_DST, "ipv6_dst", 0) \
550 FIELD(F_ND_TARGET, "nd_target", FWW_ND_TARGET) \
551 FIELD(F_ND_SLL, "nd_sll", FWW_ARP_SHA) \
552 FIELD(F_ND_TLL, "nd_tll", FWW_ARP_THA)
555 #define FIELD(ENUM, NAME, WILDCARD) ENUM,
562 enum field_index index;
564 flow_wildcards_t wildcard; /* FWW_* bit. */
568 parse_field_name(const char *name, const struct field **f_out)
570 static const struct field fields[N_FIELDS] = {
571 #define FIELD(ENUM, NAME, WILDCARD) { ENUM, NAME, WILDCARD },
575 const struct field *f;
577 for (f = fields; f < &fields[ARRAY_SIZE(fields)]; f++) {
578 if (!strcmp(f->name, name)) {
588 parse_field_value(struct cls_rule *rule, enum field_index index,
591 uint8_t mac[ETH_ADDR_LEN];
592 ovs_be64 tun_id, tun_mask;
594 struct in6_addr ipv6, ipv6_mask;
599 str_to_tun_id(value, &tun_id, &tun_mask);
600 cls_rule_set_tun_id_masked(rule, tun_id, tun_mask);
604 if (!parse_port_name(value, &port_no)) {
605 port_no = atoi(value);
607 if (port_no == OFPP_LOCAL) {
608 port_no = ODPP_LOCAL;
610 cls_rule_set_in_port(rule, port_no);
614 cls_rule_set_dl_vlan(rule, htons(str_to_u32(value)));
618 cls_rule_set_dl_vlan_pcp(rule, str_to_u32(value));
622 str_to_mac(value, mac);
623 cls_rule_set_dl_src(rule, mac);
627 str_to_mac(value, mac);
628 cls_rule_set_dl_dst(rule, mac);
632 cls_rule_set_dl_type(rule, htons(str_to_u32(value)));
636 str_to_ip(value, &ip, &mask);
637 cls_rule_set_nw_src_masked(rule, ip, mask);
641 str_to_ip(value, &ip, &mask);
642 cls_rule_set_nw_dst_masked(rule, ip, mask);
646 cls_rule_set_nw_proto(rule, str_to_u32(value));
650 cls_rule_set_nw_tos(rule, str_to_u32(value));
654 cls_rule_set_tp_src(rule, htons(str_to_u32(value)));
658 cls_rule_set_tp_dst(rule, htons(str_to_u32(value)));
662 cls_rule_set_icmp_type(rule, str_to_u32(value));
666 cls_rule_set_icmp_code(rule, str_to_u32(value));
670 str_to_mac(value, mac);
671 cls_rule_set_arp_sha(rule, mac);
675 str_to_mac(value, mac);
676 cls_rule_set_arp_tha(rule, mac);
680 str_to_ipv6(value, &ipv6, &ipv6_mask);
681 cls_rule_set_ipv6_src_masked(rule, &ipv6, &ipv6_mask);
685 str_to_ipv6(value, &ipv6, &ipv6_mask);
686 cls_rule_set_ipv6_dst_masked(rule, &ipv6, &ipv6_mask);
690 str_to_ipv6(value, &ipv6, NULL);
691 cls_rule_set_nd_target(rule, ipv6);
695 str_to_mac(value, mac);
696 cls_rule_set_arp_sha(rule, mac);
700 str_to_mac(value, mac);
701 cls_rule_set_arp_tha(rule, mac);
710 parse_reg_value(struct cls_rule *rule, int reg_idx, const char *value)
712 uint32_t reg_value, reg_mask;
714 if (!strcmp(value, "ANY") || !strcmp(value, "*")) {
715 cls_rule_set_reg_masked(rule, reg_idx, 0, 0);
716 } else if (sscanf(value, "%"SCNi32"/%"SCNi32,
717 ®_value, ®_mask) == 2) {
718 cls_rule_set_reg_masked(rule, reg_idx, reg_value, reg_mask);
719 } else if (sscanf(value, "%"SCNi32, ®_value)) {
720 cls_rule_set_reg(rule, reg_idx, reg_value);
722 ovs_fatal(0, "register fields must take the form <value> "
723 "or <value>/<mask>");
727 /* Convert 'string' (as described in the Flow Syntax section of the ovs-ofctl
728 * man page) into 'pf'. If 'actions' is specified, an action must be in
729 * 'string' and may be expanded or reallocated. */
731 parse_ofp_str(struct flow_mod *fm, uint8_t *table_idx,
732 struct ofpbuf *actions, char *string)
734 char *save_ptr = NULL;
740 cls_rule_init_catchall(&fm->cr, OFP_DEFAULT_PRIORITY);
741 fm->cookie = htonll(0);
742 fm->command = UINT16_MAX;
743 fm->idle_timeout = OFP_FLOW_PERMANENT;
744 fm->hard_timeout = OFP_FLOW_PERMANENT;
745 fm->buffer_id = UINT32_MAX;
746 fm->out_port = OFPP_NONE;
749 char *act_str = strstr(string, "action");
751 ovs_fatal(0, "must specify an action");
755 act_str = strchr(act_str + 1, '=');
757 ovs_fatal(0, "must specify an action");
762 str_to_action(act_str, actions);
763 fm->actions = actions->data;
764 fm->n_actions = actions->size / sizeof(union ofp_action);
769 for (name = strtok_r(string, "=, \t\r\n", &save_ptr); name;
770 name = strtok_r(NULL, "=, \t\r\n", &save_ptr)) {
771 const struct protocol *p;
773 if (parse_protocol(name, &p)) {
774 cls_rule_set_dl_type(&fm->cr, htons(p->dl_type));
776 cls_rule_set_nw_proto(&fm->cr, p->nw_proto);
779 const struct field *f;
782 value = strtok_r(NULL, ", \t\r\n", &save_ptr);
784 ovs_fatal(0, "field %s missing value", name);
787 if (table_idx && !strcmp(name, "table")) {
788 *table_idx = atoi(value);
789 } else if (!strcmp(name, "out_port")) {
790 fm->out_port = atoi(value);
791 } else if (!strcmp(name, "priority")) {
792 fm->cr.priority = atoi(value);
793 } else if (!strcmp(name, "idle_timeout")) {
794 fm->idle_timeout = atoi(value);
795 } else if (!strcmp(name, "hard_timeout")) {
796 fm->hard_timeout = atoi(value);
797 } else if (!strcmp(name, "cookie")) {
798 fm->cookie = htonll(str_to_u64(value));
799 } else if (parse_field_name(name, &f)) {
800 if (!strcmp(value, "*") || !strcmp(value, "ANY")) {
802 fm->cr.wc.wildcards |= f->wildcard;
803 cls_rule_zero_wildcarded_fields(&fm->cr);
804 } else if (f->index == F_NW_SRC) {
805 cls_rule_set_nw_src_masked(&fm->cr, 0, 0);
806 } else if (f->index == F_NW_DST) {
807 cls_rule_set_nw_dst_masked(&fm->cr, 0, 0);
808 } else if (f->index == F_IPV6_SRC) {
809 cls_rule_set_ipv6_src_masked(&fm->cr,
810 &in6addr_any, &in6addr_any);
811 } else if (f->index == F_IPV6_DST) {
812 cls_rule_set_ipv6_dst_masked(&fm->cr,
813 &in6addr_any, &in6addr_any);
814 } else if (f->index == F_DL_VLAN) {
815 cls_rule_set_any_vid(&fm->cr);
816 } else if (f->index == F_DL_VLAN_PCP) {
817 cls_rule_set_any_pcp(&fm->cr);
822 parse_field_value(&fm->cr, f->index, value);
824 } else if (!strncmp(name, "reg", 3)
825 && isdigit((unsigned char) name[3])) {
826 unsigned int reg_idx = atoi(name + 3);
827 if (reg_idx >= FLOW_N_REGS) {
828 ovs_fatal(0, "only %d registers supported", FLOW_N_REGS);
830 parse_reg_value(&fm->cr, reg_idx, value);
832 ovs_fatal(0, "unknown keyword %s", name);
838 /* Parses 'string' as an OFPT_FLOW_MOD or NXT_FLOW_MOD with command 'command'
839 * (one of OFPFC_*) and appends the parsed OpenFlow message to 'packets'.
840 * '*cur_format' should initially contain the flow format currently configured
841 * on the connection; this function will add a message to change the flow
842 * format and update '*cur_format', if this is necessary to add the parsed
845 parse_ofp_flow_mod_str(struct list *packets, enum nx_flow_format *cur_format,
846 char *string, uint16_t command)
848 bool is_del = command == OFPFC_DELETE || command == OFPFC_DELETE_STRICT;
849 enum nx_flow_format min_format, next_format;
850 struct ofpbuf actions;
854 ofpbuf_init(&actions, 64);
855 parse_ofp_str(&fm, NULL, is_del ? NULL : &actions, string);
856 fm.command = command;
858 min_format = ofputil_min_flow_format(&fm.cr, true, fm.cookie);
859 next_format = MAX(*cur_format, min_format);
860 if (next_format != *cur_format) {
861 struct ofpbuf *sff = ofputil_make_set_flow_format(next_format);
862 list_push_back(packets, &sff->list_node);
863 *cur_format = next_format;
866 ofm = ofputil_encode_flow_mod(&fm, *cur_format);
867 list_push_back(packets, &ofm->list_node);
869 ofpbuf_uninit(&actions);
872 /* Similar to parse_ofp_flow_mod_str(), except that the string is read from
873 * 'stream' and the command is always OFPFC_ADD. Returns false if end-of-file
874 * is reached before reading a flow, otherwise true. */
876 parse_ofp_flow_mod_file(struct list *packets, enum nx_flow_format *cur,
877 FILE *stream, uint16_t command)
883 ok = ds_get_preprocessed_line(&s, stream) == 0;
885 parse_ofp_flow_mod_str(packets, cur, ds_cstr(&s), command);
893 parse_ofp_flow_stats_request_str(struct flow_stats_request *fsr,
894 bool aggregate, char *string)
899 parse_ofp_str(&fm, &table_id, NULL, string);
900 fsr->aggregate = aggregate;
902 fsr->out_port = fm.out_port;
903 fsr->table_id = table_id;