ofproto: New action TTL decrement.
[sliver-openvswitch.git] / lib / ofp-parse.c
1 /*
2  * Copyright (c) 2010, 2011 Nicira Networks.
3  *
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:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #include <config.h>
18
19 #include "ofp-parse.h"
20
21 #include <ctype.h>
22 #include <errno.h>
23 #include <stdlib.h>
24
25 #include "autopath.h"
26 #include "bundle.h"
27 #include "byte-order.h"
28 #include "dynamic-string.h"
29 #include "learn.h"
30 #include "meta-flow.h"
31 #include "netdev.h"
32 #include "multipath.h"
33 #include "nx-match.h"
34 #include "ofp-util.h"
35 #include "ofpbuf.h"
36 #include "openflow/openflow.h"
37 #include "packets.h"
38 #include "socket-util.h"
39 #include "vconn.h"
40 #include "vlog.h"
41
42 VLOG_DEFINE_THIS_MODULE(ofp_parse);
43
44 static uint8_t
45 str_to_table_id(const char *str)
46 {
47     int table_id;
48
49     if (!str_to_int(str, 10, &table_id) || table_id < 0 || table_id > 255) {
50         ovs_fatal(0, "invalid table \"%s\"", str);
51     }
52     return table_id;
53 }
54
55 static uint16_t
56 str_to_u16(const char *str, const char *name)
57 {
58     int value;
59
60     if (!str_to_int(str, 0, &value) || value < 0 || value > 65535) {
61         ovs_fatal(0, "invalid %s \"%s\"", name, str);
62     }
63     return value;
64 }
65
66 static uint32_t
67 str_to_u32(const char *str)
68 {
69     char *tail;
70     uint32_t value;
71
72     if (!str[0]) {
73         ovs_fatal(0, "missing required numeric argument");
74     }
75
76     errno = 0;
77     value = strtoul(str, &tail, 0);
78     if (errno == EINVAL || errno == ERANGE || *tail) {
79         ovs_fatal(0, "invalid numeric format %s", str);
80     }
81     return value;
82 }
83
84 static uint64_t
85 str_to_u64(const char *str)
86 {
87     char *tail;
88     uint64_t value;
89
90     if (!str[0]) {
91         ovs_fatal(0, "missing required numeric argument");
92     }
93
94     errno = 0;
95     value = strtoull(str, &tail, 0);
96     if (errno == EINVAL || errno == ERANGE || *tail) {
97         ovs_fatal(0, "invalid numeric format %s", str);
98     }
99     return value;
100 }
101
102 static void
103 str_to_mac(const char *str, uint8_t mac[6])
104 {
105     if (sscanf(str, ETH_ADDR_SCAN_FMT, ETH_ADDR_SCAN_ARGS(mac))
106         != ETH_ADDR_SCAN_COUNT) {
107         ovs_fatal(0, "invalid mac address %s", str);
108     }
109 }
110
111 static void
112 str_to_ip(const char *str, ovs_be32 *ip)
113 {
114     struct in_addr in_addr;
115
116     if (lookup_ip(str, &in_addr)) {
117         ovs_fatal(0, "%s: could not convert to IP address", str);
118     }
119     *ip = in_addr.s_addr;
120 }
121
122 static struct ofp_action_output *
123 put_output_action(struct ofpbuf *b, uint16_t port)
124 {
125     struct ofp_action_output *oao;
126
127     oao = ofputil_put_OFPAT_OUTPUT(b);
128     oao->port = htons(port);
129     return oao;
130 }
131
132 static void
133 parse_enqueue(struct ofpbuf *b, char *arg)
134 {
135     char *sp = NULL;
136     char *port = strtok_r(arg, ":q", &sp);
137     char *queue = strtok_r(NULL, "", &sp);
138     struct ofp_action_enqueue *oae;
139
140     if (port == NULL || queue == NULL) {
141         ovs_fatal(0, "\"enqueue\" syntax is \"enqueue:PORT:QUEUE\"");
142     }
143
144     oae = ofputil_put_OFPAT_ENQUEUE(b);
145     oae->port = htons(str_to_u32(port));
146     oae->queue_id = htonl(str_to_u32(queue));
147 }
148
149 static void
150 parse_output(struct ofpbuf *b, char *arg)
151 {
152     if (strchr(arg, '[')) {
153         struct nx_action_output_reg *naor;
154         int ofs, n_bits;
155         uint32_t src;
156
157         nxm_parse_field_bits(arg, &src, &ofs, &n_bits);
158
159         naor = ofputil_put_NXAST_OUTPUT_REG(b);
160         naor->ofs_nbits = nxm_encode_ofs_nbits(ofs, n_bits);
161         naor->src = htonl(src);
162         naor->max_len = htons(UINT16_MAX);
163     } else {
164         put_output_action(b, str_to_u32(arg));
165     }
166 }
167
168 static void
169 parse_resubmit(struct ofpbuf *b, char *arg)
170 {
171     struct nx_action_resubmit *nar;
172     char *in_port_s, *table_s;
173     uint16_t in_port;
174     uint8_t table;
175
176     in_port_s = strsep(&arg, ",");
177     if (in_port_s && in_port_s[0]) {
178         if (!ofputil_port_from_string(in_port_s, &in_port)) {
179             in_port = str_to_u32(in_port_s);
180         }
181     } else {
182         in_port = OFPP_IN_PORT;
183     }
184
185     table_s = strsep(&arg, ",");
186     table = table_s && table_s[0] ? str_to_u32(table_s) : 255;
187
188     if (in_port == OFPP_IN_PORT && table == 255) {
189         ovs_fatal(0, "at least one \"in_port\" or \"table\" must be specified "
190                   " on resubmit");
191     }
192
193     if (in_port != OFPP_IN_PORT && table == 255) {
194         nar = ofputil_put_NXAST_RESUBMIT(b);
195     } else {
196         nar = ofputil_put_NXAST_RESUBMIT_TABLE(b);
197         nar->table = table;
198     }
199     nar->in_port = htons(in_port);
200 }
201
202 static void
203 parse_set_tunnel(struct ofpbuf *b, const char *arg)
204 {
205     uint64_t tun_id = str_to_u64(arg);
206     if (tun_id > UINT32_MAX) {
207         ofputil_put_NXAST_SET_TUNNEL64(b)->tun_id = htonll(tun_id);
208     } else {
209         ofputil_put_NXAST_SET_TUNNEL(b)->tun_id = htonl(tun_id);
210     }
211 }
212
213 static void
214 parse_note(struct ofpbuf *b, const char *arg)
215 {
216     size_t start_ofs = b->size;
217     struct nx_action_note *nan;
218     int remainder;
219     size_t len;
220
221     nan = ofputil_put_NXAST_NOTE(b);
222
223     b->size -= sizeof nan->note;
224     while (*arg != '\0') {
225         uint8_t byte;
226         bool ok;
227
228         if (*arg == '.') {
229             arg++;
230         }
231         if (*arg == '\0') {
232             break;
233         }
234
235         byte = hexits_value(arg, 2, &ok);
236         if (!ok) {
237             ovs_fatal(0, "bad hex digit in `note' argument");
238         }
239         ofpbuf_put(b, &byte, 1);
240
241         arg += 2;
242     }
243
244     len = b->size - start_ofs;
245     remainder = len % OFP_ACTION_ALIGN;
246     if (remainder) {
247         ofpbuf_put_zeros(b, OFP_ACTION_ALIGN - remainder);
248     }
249     nan = (struct nx_action_note *)((char *)b->data + start_ofs);
250     nan->len = htons(b->size - start_ofs);
251 }
252
253 static void
254 parse_named_action(enum ofputil_action_code code, const struct flow *flow,
255                    struct ofpbuf *b, char *arg)
256 {
257     struct ofp_action_dl_addr *oada;
258     struct ofp_action_vlan_pcp *oavp;
259     struct ofp_action_vlan_vid *oavv;
260     struct ofp_action_nw_addr *oana;
261     struct ofp_action_tp_port *oata;
262
263     switch (code) {
264     case OFPUTIL_OFPAT_OUTPUT:
265         parse_output(b, arg);
266         break;
267
268     case OFPUTIL_OFPAT_SET_VLAN_VID:
269         oavv = ofputil_put_OFPAT_SET_VLAN_VID(b);
270         oavv->vlan_vid = htons(str_to_u32(arg));
271         break;
272
273     case OFPUTIL_OFPAT_SET_VLAN_PCP:
274         oavp = ofputil_put_OFPAT_SET_VLAN_PCP(b);
275         oavp->vlan_pcp = str_to_u32(arg);
276         break;
277
278     case OFPUTIL_OFPAT_STRIP_VLAN:
279         ofputil_put_OFPAT_STRIP_VLAN(b);
280         break;
281
282     case OFPUTIL_OFPAT_SET_DL_SRC:
283     case OFPUTIL_OFPAT_SET_DL_DST:
284         oada = ofputil_put_action(code, b);
285         str_to_mac(arg, oada->dl_addr);
286         break;
287
288     case OFPUTIL_OFPAT_SET_NW_SRC:
289     case OFPUTIL_OFPAT_SET_NW_DST:
290         oana = ofputil_put_action(code, b);
291         str_to_ip(arg, &oana->nw_addr);
292         break;
293
294     case OFPUTIL_OFPAT_SET_NW_TOS:
295         ofputil_put_OFPAT_SET_NW_TOS(b)->nw_tos = str_to_u32(arg);
296         break;
297
298     case OFPUTIL_OFPAT_SET_TP_SRC:
299     case OFPUTIL_OFPAT_SET_TP_DST:
300         oata = ofputil_put_action(code, b);
301         oata->tp_port = htons(str_to_u32(arg));
302         break;
303
304     case OFPUTIL_OFPAT_ENQUEUE:
305         parse_enqueue(b, arg);
306         break;
307
308     case OFPUTIL_NXAST_RESUBMIT:
309         parse_resubmit(b, arg);
310         break;
311
312     case OFPUTIL_NXAST_SET_TUNNEL:
313         parse_set_tunnel(b, arg);
314         break;
315
316     case OFPUTIL_NXAST_SET_QUEUE:
317         ofputil_put_NXAST_SET_QUEUE(b)->queue_id = htonl(str_to_u32(arg));
318         break;
319
320     case OFPUTIL_NXAST_POP_QUEUE:
321         ofputil_put_NXAST_POP_QUEUE(b);
322         break;
323
324     case OFPUTIL_NXAST_REG_MOVE:
325         nxm_parse_reg_move(ofputil_put_NXAST_REG_MOVE(b), arg);
326         break;
327
328     case OFPUTIL_NXAST_REG_LOAD:
329         nxm_parse_reg_load(ofputil_put_NXAST_REG_LOAD(b), arg);
330         break;
331
332     case OFPUTIL_NXAST_NOTE:
333         parse_note(b, arg);
334         break;
335
336     case OFPUTIL_NXAST_SET_TUNNEL64:
337         ofputil_put_NXAST_SET_TUNNEL64(b)->tun_id = htonll(str_to_u64(arg));
338         break;
339
340     case OFPUTIL_NXAST_MULTIPATH:
341         multipath_parse(ofputil_put_NXAST_MULTIPATH(b), arg);
342         break;
343
344     case OFPUTIL_NXAST_AUTOPATH:
345         autopath_parse(ofputil_put_NXAST_AUTOPATH(b), arg);
346         break;
347
348     case OFPUTIL_NXAST_BUNDLE:
349         bundle_parse(b, arg);
350         break;
351
352     case OFPUTIL_NXAST_BUNDLE_LOAD:
353         bundle_parse_load(b, arg);
354         break;
355
356     case OFPUTIL_NXAST_RESUBMIT_TABLE:
357     case OFPUTIL_NXAST_OUTPUT_REG:
358         NOT_REACHED();
359
360     case OFPUTIL_NXAST_LEARN:
361         learn_parse(b, arg, flow);
362         break;
363
364     case OFPUTIL_NXAST_EXIT:
365         ofputil_put_NXAST_EXIT(b);
366         break;
367
368     case OFPUTIL_NXAST_DEC_TTL:
369         ofputil_put_NXAST_DEC_TTL(b);
370         break;
371     }
372 }
373
374 static void
375 str_to_action(const struct flow *flow, char *str, struct ofpbuf *b)
376 {
377     char *pos, *act, *arg;
378     int n_actions;
379
380     pos = str;
381     n_actions = 0;
382     while (ofputil_parse_key_value(&pos, &act, &arg)) {
383         uint16_t port;
384         int code;
385
386         code = ofputil_action_code_from_name(act);
387         if (code >= 0) {
388             parse_named_action(code, flow, b, arg);
389         } else if (!strcasecmp(act, "drop")) {
390             /* A drop action in OpenFlow occurs by just not setting
391              * an action. */
392             if (n_actions) {
393                 ovs_fatal(0, "Drop actions must not be preceded by other "
394                           "actions");
395             } else if (ofputil_parse_key_value(&pos, &act, &arg)) {
396                 ovs_fatal(0, "Drop actions must not be followed by other "
397                           "actions");
398             }
399             break;
400         } else if (!strcasecmp(act, "CONTROLLER")) {
401             struct ofp_action_output *oao;
402             oao = put_output_action(b, OFPP_CONTROLLER);
403
404             /* Unless a numeric argument is specified, we send the whole
405              * packet to the controller. */
406             if (arg[0] && (strspn(arg, "0123456789") == strlen(arg))) {
407                oao->max_len = htons(str_to_u32(arg));
408             } else {
409                 oao->max_len = htons(UINT16_MAX);
410             }
411         } else if (ofputil_port_from_string(act, &port)) {
412             put_output_action(b, port);
413         } else {
414             ovs_fatal(0, "Unknown action: %s", act);
415         }
416         n_actions++;
417     }
418 }
419
420 struct protocol {
421     const char *name;
422     uint16_t dl_type;
423     uint8_t nw_proto;
424 };
425
426 static bool
427 parse_protocol(const char *name, const struct protocol **p_out)
428 {
429     static const struct protocol protocols[] = {
430         { "ip", ETH_TYPE_IP, 0 },
431         { "arp", ETH_TYPE_ARP, 0 },
432         { "icmp", ETH_TYPE_IP, IPPROTO_ICMP },
433         { "tcp", ETH_TYPE_IP, IPPROTO_TCP },
434         { "udp", ETH_TYPE_IP, IPPROTO_UDP },
435         { "ipv6", ETH_TYPE_IPV6, 0 },
436         { "ip6", ETH_TYPE_IPV6, 0 },
437         { "icmp6", ETH_TYPE_IPV6, IPPROTO_ICMPV6 },
438         { "tcp6", ETH_TYPE_IPV6, IPPROTO_TCP },
439         { "udp6", ETH_TYPE_IPV6, IPPROTO_UDP },
440     };
441     const struct protocol *p;
442
443     for (p = protocols; p < &protocols[ARRAY_SIZE(protocols)]; p++) {
444         if (!strcmp(p->name, name)) {
445             *p_out = p;
446             return true;
447         }
448     }
449     *p_out = NULL;
450     return false;
451 }
452
453 static void
454 ofp_fatal(const char *flow, bool verbose, const char *format, ...)
455 {
456     va_list args;
457
458     if (verbose) {
459         fprintf(stderr, "%s:\n", flow);
460     }
461
462     va_start(args, format);
463     ovs_fatal_valist(0, format, args);
464 }
465
466 static void
467 parse_field(const struct mf_field *mf, const char *s, struct cls_rule *rule)
468 {
469     union mf_value value, mask;
470     char *error;
471
472     error = mf_parse(mf, s, &value, &mask);
473     if (error) {
474         ovs_fatal(0, "%s", error);
475     }
476
477     mf_set(mf, &value, &mask, rule);
478 }
479
480 /* Convert 'str_' (as described in the Flow Syntax section of the ovs-ofctl man
481  * page) into 'fm' for sending the specified flow_mod 'command' to a switch.
482  * If 'actions' is specified, an action must be in 'string' and may be expanded
483  * or reallocated.
484  *
485  * To parse syntax for an OFPT_FLOW_MOD (or NXT_FLOW_MOD), use an OFPFC_*
486  * constant for 'command'.  To parse syntax for an OFPST_FLOW or
487  * OFPST_AGGREGATE (or NXST_FLOW or NXST_AGGREGATE), use -1 for 'command'. */
488 void
489 parse_ofp_str(struct ofputil_flow_mod *fm, int command, const char *str_,
490               bool verbose)
491 {
492     enum {
493         F_OUT_PORT = 1 << 0,
494         F_ACTIONS = 1 << 1,
495         F_TIMEOUT = 1 << 3,
496         F_PRIORITY = 1 << 4
497     } fields;
498     char *string = xstrdup(str_);
499     char *save_ptr = NULL;
500     char *act_str = NULL;
501     char *name;
502
503     switch (command) {
504     case -1:
505         fields = F_OUT_PORT;
506         break;
507
508     case OFPFC_ADD:
509         fields = F_ACTIONS | F_TIMEOUT | F_PRIORITY;
510         break;
511
512     case OFPFC_DELETE:
513         fields = F_OUT_PORT;
514         break;
515
516     case OFPFC_DELETE_STRICT:
517         fields = F_OUT_PORT | F_PRIORITY;
518         break;
519
520     case OFPFC_MODIFY:
521         fields = F_ACTIONS;
522         break;
523
524     case OFPFC_MODIFY_STRICT:
525         fields = F_ACTIONS | F_PRIORITY;
526         break;
527
528     default:
529         NOT_REACHED();
530     }
531
532     cls_rule_init_catchall(&fm->cr, OFP_DEFAULT_PRIORITY);
533     fm->cookie = htonll(0);
534     fm->cookie_mask = htonll(0);
535     fm->table_id = 0xff;
536     fm->command = command;
537     fm->idle_timeout = OFP_FLOW_PERMANENT;
538     fm->hard_timeout = OFP_FLOW_PERMANENT;
539     fm->buffer_id = UINT32_MAX;
540     fm->out_port = OFPP_NONE;
541     fm->flags = 0;
542     if (fields & F_ACTIONS) {
543         act_str = strstr(string, "action");
544         if (!act_str) {
545             ofp_fatal(str_, verbose, "must specify an action");
546         }
547         *act_str = '\0';
548
549         act_str = strchr(act_str + 1, '=');
550         if (!act_str) {
551             ofp_fatal(str_, verbose, "must specify an action");
552         }
553
554         act_str++;
555     }
556     for (name = strtok_r(string, "=, \t\r\n", &save_ptr); name;
557          name = strtok_r(NULL, "=, \t\r\n", &save_ptr)) {
558         const struct protocol *p;
559
560         if (parse_protocol(name, &p)) {
561             cls_rule_set_dl_type(&fm->cr, htons(p->dl_type));
562             if (p->nw_proto) {
563                 cls_rule_set_nw_proto(&fm->cr, p->nw_proto);
564             }
565         } else {
566             char *value;
567
568             value = strtok_r(NULL, ", \t\r\n", &save_ptr);
569             if (!value) {
570                 ofp_fatal(str_, verbose, "field %s missing value", name);
571             }
572
573             if (!strcmp(name, "table")) {
574                 fm->table_id = str_to_table_id(value);
575             } else if (!strcmp(name, "out_port")) {
576                 fm->out_port = atoi(value);
577             } else if (fields & F_PRIORITY && !strcmp(name, "priority")) {
578                 fm->cr.priority = str_to_u16(value, name);
579             } else if (fields & F_TIMEOUT && !strcmp(name, "idle_timeout")) {
580                 fm->idle_timeout = str_to_u16(value, name);
581             } else if (fields & F_TIMEOUT && !strcmp(name, "hard_timeout")) {
582                 fm->hard_timeout = str_to_u16(value, name);
583             } else if (!strcmp(name, "cookie")) {
584                 char *mask = strchr(value, '/');
585                 if (mask) {
586                     if (command == OFPFC_ADD) {
587                         ofp_fatal(str_, verbose, "flow additions cannot use "
588                                   "a cookie mask");
589                     }
590                     *mask = '\0';
591                     fm->cookie_mask = htonll(str_to_u64(mask+1));
592                 } else {
593                     fm->cookie_mask = htonll(UINT64_MAX);
594                 }
595                 fm->cookie = htonll(str_to_u64(value));
596             } else if (mf_from_name(name)) {
597                 parse_field(mf_from_name(name), value, &fm->cr);
598             } else if (!strcmp(name, "duration")
599                        || !strcmp(name, "n_packets")
600                        || !strcmp(name, "n_bytes")) {
601                 /* Ignore these, so that users can feed the output of
602                  * "ovs-ofctl dump-flows" back into commands that parse
603                  * flows. */
604             } else {
605                 ofp_fatal(str_, verbose, "unknown keyword %s", name);
606             }
607         }
608     }
609     if (fields & F_ACTIONS) {
610         struct ofpbuf actions;
611
612         ofpbuf_init(&actions, sizeof(union ofp_action));
613         str_to_action(&fm->cr.flow, act_str, &actions);
614         fm->actions = ofpbuf_steal_data(&actions);
615         fm->n_actions = actions.size / sizeof(union ofp_action);
616     } else {
617         fm->actions = NULL;
618         fm->n_actions = 0;
619     }
620
621     free(string);
622 }
623
624 /* Parses 'string' as an OFPT_FLOW_MOD or NXT_FLOW_MOD with command 'command'
625  * (one of OFPFC_*) and appends the parsed OpenFlow message to 'packets'.
626  * '*cur_format' should initially contain the flow format currently configured
627  * on the connection; this function will add a message to change the flow
628  * format and update '*cur_format', if this is necessary to add the parsed
629  * flow. */
630 void
631 parse_ofp_flow_mod_str(struct list *packets, enum nx_flow_format *cur_format,
632                        bool *flow_mod_table_id, char *string, uint16_t command,
633                        bool verbose)
634 {
635     enum nx_flow_format min_format, next_format;
636     struct cls_rule rule_copy;
637     struct ofpbuf *ofm;
638     struct ofputil_flow_mod fm;
639
640     parse_ofp_str(&fm, command, string, verbose);
641
642     min_format = ofputil_min_flow_format(&fm.cr);
643     if (command != OFPFC_ADD && fm.cookie_mask != htonll(0)) {
644         min_format = NXFF_NXM;
645     }
646     next_format = MAX(*cur_format, min_format);
647     if (next_format != *cur_format) {
648         struct ofpbuf *sff = ofputil_make_set_flow_format(next_format);
649         list_push_back(packets, &sff->list_node);
650         *cur_format = next_format;
651     }
652
653     /* Normalize a copy of the rule.  This ensures that non-normalized flows
654      * get logged but doesn't affect what gets sent to the switch, so that the
655      * switch can do whatever it likes with the flow. */
656     rule_copy = fm.cr;
657     ofputil_normalize_rule(&rule_copy, next_format);
658
659     if (fm.table_id != 0xff && !*flow_mod_table_id) {
660         struct ofpbuf *sff = ofputil_make_flow_mod_table_id(true);
661         list_push_back(packets, &sff->list_node);
662         *flow_mod_table_id = true;
663     }
664
665     ofm = ofputil_encode_flow_mod(&fm, *cur_format, *flow_mod_table_id);
666     list_push_back(packets, &ofm->list_node);
667 }
668
669 /* Similar to parse_ofp_flow_mod_str(), except that the string is read from
670  * 'stream' and the command is always OFPFC_ADD.  Returns false if end-of-file
671  * is reached before reading a flow, otherwise true. */
672 bool
673 parse_ofp_flow_mod_file(struct list *packets,
674                         enum nx_flow_format *cur, bool *flow_mod_table_id,
675                         FILE *stream, uint16_t command)
676 {
677     struct ds s;
678     bool ok;
679
680     ds_init(&s);
681     ok = ds_get_preprocessed_line(&s, stream) == 0;
682     if (ok) {
683         parse_ofp_flow_mod_str(packets, cur, flow_mod_table_id,
684                                ds_cstr(&s), command, true);
685     }
686     ds_destroy(&s);
687
688     return ok;
689 }
690
691 void
692 parse_ofp_flow_stats_request_str(struct ofputil_flow_stats_request *fsr,
693                                  bool aggregate, char *string)
694 {
695     struct ofputil_flow_mod fm;
696
697     parse_ofp_str(&fm, -1, string, false);
698     fsr->aggregate = aggregate;
699     fsr->cookie = fm.cookie;
700     fsr->cookie_mask = fm.cookie_mask;
701     fsr->match = fm.cr;
702     fsr->out_port = fm.out_port;
703     fsr->table_id = fm.table_id;
704 }