module sal-flow {
    namespace "urn:opendaylight:flow:service";
    prefix flow;

    import yang-ext {prefix ext; revision-date "2013-07-09";}
    import opendaylight-inventory {prefix inv;revision-date "2013-08-19";}
    import opendaylight-flow-types {prefix types;revision-date "2013-10-26";}
    import opendaylight-group-types {prefix group-type;revision-date "2013-10-18";}
    import opendaylight-meter-types {prefix meter-type;revision-date "2013-09-18";}
    import flow-capable-transaction {prefix tr; revision-date "2015-03-04";}
    import flow-errors {prefix error; revision-date "2013-11-16";}

    description "Openflow flow management.";

    revision "2013-08-19" {
        description "Initial revision of flow service";
    }

    typedef flow-table-ref {
        description "Openflow table identifier";
        type instance-identifier;
    }

    grouping node-flow-removed {
        description "Flow removed message structure.";
        leaf node {
            // TODO:: replace with inv:node-context-ref
            ext:context-reference "inv:node-context";
            type inv:node-ref;
        }
        leaf flow-table {
            type flow-table-ref;
        }
        uses types:flow-mod-removed;
    }

    grouping node-flow {
        description "Top openflow flow structure suitable for rpc input (contains node-context).";
        uses "inv:node-context-ref";

        leaf flow-table {
            type flow-table-ref;
        }
        uses types:flow;
    }

    grouping base-node-error-notification {
        description "Openflow error message general structure.";
        status deprecated;
        leaf node {
            ext:context-reference "inv:node-context";
                type inv:node-ref;
        }
    }

    grouping node-error-reference {
        description "Error message binding - to which source type the error belongs.";
        choice object-reference {
            case flow-ref{
                leaf flow-ref {
                        type types:flow-ref;
                }
            }
            case group-ref{
                leaf group-ref {
                    type group-type:group-ref;
                }
            }
            case meter-ref{
                leaf meter-ref {
                    type meter-type:meter-ref;
                }
            }
        }
    }

    grouping flow-update {
        description "DataStore aware flow update structure suitable for rpc input (contains node-context).";
        uses "inv:node-context-ref";

        container original-flow {
            uses types:flow;
        }
        container updated-flow {
            uses types:flow;
        }
    }

    rpc add-flow {
        description "Adding flow to openflow device.";
        input {
            uses tr:transaction-metadata;
            leaf flow-ref {
                type types:flow-ref;
            }
            uses node-flow;
        }
        output {
            uses tr:transaction-aware;
        }
    }

    rpc remove-flow {
        description "Removing flow from openflow device.";
        input {
            uses tr:transaction-metadata;
            leaf flow-ref {
                type types:flow-ref;
            }
            uses node-flow;
        }
        output {
            uses tr:transaction-aware;
        }
    }

    rpc update-flow {
        description "Updating flow on openflow device.";
        input {
            uses tr:transaction-metadata;
            leaf flow-ref {
                type types:flow-ref;
            }
            uses flow-update;
        }
        output {
            uses tr:transaction-aware;
        }
    }

    notification flow-added {
        status deprecated;

        uses tr:transaction-metadata;
        leaf flow-ref {
            type types:flow-ref;
        }
        uses node-flow;
        uses tr:transaction-aware;
    }

    notification flow-updated {
        status deprecated;

        uses tr:transaction-metadata;
        leaf flow-ref {
            type types:flow-ref;
        }
        uses node-flow;
        uses tr:transaction-aware;
    }

    notification flow-removed {
        status deprecated;

        uses tr:transaction-metadata;
        leaf flow-ref {
            type types:flow-ref;
        }
        leaf reason {
            type types:removed-flow-reason;
        }
        uses node-flow;
        uses tr:transaction-aware;
    }

    notification switch-flow-removed {
        status deprecated;

        uses node-flow-removed;
    }

    notification node-error-notification {
        status deprecated;

        uses error:error-message;
        uses tr:transaction-aware;
        uses tr:transaction-metadata;
        uses node-error-reference;
        uses base-node-error-notification;
    }

    notification node-experimenter-error-notification {
        status deprecated;

        uses error:experimenter-error-message;
        uses tr:transaction-aware;
    }
}