blob: bddbc8d5ab4297c34f003fe4ee2e0cff8343bdc2 [file] [log] [blame]
Rich Lanea06d0c32013-03-25 08:52:03 -07001:: # Copyright 2013, Big Switch Networks, Inc.
2:: #
3:: # LoxiGen is licensed under the Eclipse Public License, version 1.0 (EPL), with
4:: # the following special exception:
5:: #
6:: # LOXI Exception
7:: #
8:: # As a special exception to the terms of the EPL, you may distribute libraries
9:: # generated by LoxiGen (LoxiGen Libraries) under the terms of your choice, provided
10:: # that copyright and licensing notices generated by LoxiGen are not altered or removed
11:: # from the LoxiGen Libraries and the notice provided below is (i) included in
12:: # the LoxiGen Libraries, if distributed in source code form and (ii) included in any
13:: # documentation for the LoxiGen Libraries, if distributed in binary form.
14:: #
15:: # Notice: "Copyright 2013, Big Switch Networks, Inc. This library was generated by the LoxiGen Compiler."
16:: #
17:: # You may not use this file except in compliance with the EPL or LOXI Exception. You may obtain
18:: # a copy of the EPL at:
19:: #
20:: # http://www.eclipse.org/legal/epl-v10.html
21:: #
22:: # Unless required by applicable law or agreed to in writing, software
23:: # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
24:: # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
25:: # EPL for the specific language governing permissions and limitations
26:: # under the EPL.
27::
Rich Laned983aa52013-06-13 11:48:37 -070028:: include('_copyright.c')
Rich Lanea06d0c32013-03-25 08:52:03 -070029
30/****************************************************************
31 * File: of_utils.h
32 *
33 * Some utilities provided based on LOCI code generation
34 *
35 ****************************************************************/
36
37#include <loci/of_utils.h>
Rich Lanea8b54632014-02-19 11:17:47 -080038#include <stdio.h>
39#include <stdlib.h>
Rich Lanea06d0c32013-03-25 08:52:03 -070040
41
42/**
43 * Check if the given port is used as an output for any entry on the list
44 * @param actions The list of actions being checked
45 * @param outport The port being sought
46 * @returns Boolean, true if entry has an output action to outport
47 *
48 * @fixme VERSION Currently only OF 1.0 supported
49 * @fixme Check for error return in accessor
50 *
51 * If outport is "wildcard", the test should be ignored, so return true
52 */
53
54int
55of_action_list_has_out_port(of_list_action_t *actions, of_port_no_t outport)
56{
Rich Lane7fdaa5c2014-10-27 18:14:59 -070057 of_object_t elt;
Rich Lanea06d0c32013-03-25 08:52:03 -070058 of_action_output_t *output;
59 int loop_rv;
60 of_port_no_t port_no;
61 int rv = 0;
62
63 if (outport == OF_PORT_DEST_WILDCARD) { /* Same as OFPP_ANY */
64 return 1;
65 }
66
Rich Lane7fdaa5c2014-10-27 18:14:59 -070067 output = &elt;
Rich Lanea06d0c32013-03-25 08:52:03 -070068 OF_LIST_ACTION_ITER(actions, &elt, loop_rv) {
69 if (output->object_id == OF_ACTION_OUTPUT) {
70 of_action_output_port_get(output, &port_no);
71 if (port_no == outport) {
72 rv = 1;
73 break;
74 }
75 }
76 }
77
78 return rv;
79}
80
Rich Lanea8b54632014-02-19 11:17:47 -080081void
82loci_assert_fail(const char *msg, const char *file, unsigned int line)
83{
84 fprintf(stderr, "\\nASSERT %s. %s:%d\\n", msg, file, line);
85 abort();
86}