{
    "id": "ipe.json",
    "title": "Set of definitions for IPE.",
    "$schema": "http://json-schema.org/draft-04/schema#",
    "definitions": {

        "asPath": {
            "type": "object",
            "description": "The AS path regular expression used as the match condition for an IPE policy ",
            "required": [
                "regex"
            ],
            "properties": {
                "regex": {
                    "type": "string",
                    "pattern": "^[0-9{},*+?|\\-^$()\\[\\].,_ ]+$"
                }
            }
        },

        "IPEPolicy": {
            "type": "object",
            "description": "An IPE policy represents a BGP neighbor policy on the ingress node that applies [1-10] AS path prepends (priority in the model) or MED to a specific prefix.",
            "required": [
                "id",
                "node",
                "neighbor",
                "operationalStatus"
            ],
            "allOf": [
                {
                    "oneOf": [
                        { "required": ["prefix"] },
                        { "required": ["asPath"] }
                    ]
                },
                {
                    "anyOf": [
                        { "required": ["priority"] },
                        { "required": ["med"] }
                    ]
                }
            ],
            "properties": {
                "id": {
                    "description": "Program ID for the policy",
                    "$ref": "common.json#/definitions/index"
                },
                "node": {
                    "description": "Reference (nodeIndex) to the ingress node where the policy is defined",
                    "$ref": "node_v2.json#/definitions/node"
                },
                "neighbor": {
                    "description": "The neighbor node this policy applies to",
                    "$ref": "link_v2.json#/definitions/ipv4Reference"
                },
                "prefix": {
                    "description": "The prefix this policy applies to",
                    "$ref": "common.json#/definitions/ipv4Prefix"
                },
                "asPath": {
                    "description": "The AS path(s) this policy applies to",
                    "$ref": "#/definitions/asPath"
                },
                "priority": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 10,
                    "description": "Number of AS path prepends to a specific prefix"
                },
                "med": {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 4294967295,
                    "description": "Multi Exit Discriminator value for a specific prefix"
                },
                "operationalStatus": {
                    "description": "Operational Status of the policy. Up indicates the policy has been configured in the router, but is not taking effect due to other policies, Active indicates additionaly that the policy is taking effect.",
                        "oneOf": [
                        {
                            "$ref": "common.json#/definitions/operStatus"
                        },
                        {
                            "description": "Additional operation status if applicable",
                            "type": "string",
                            "enum": [
                                "Active"
                            ]
                        }
                    ]
                },
                "errorReason": {
                    "type": "string",
                    "description": "If the policy is Down or Unknown, indicates the reason."
                }
            }
        },

        "createIPEPolicy": {
            "type": "object",
            "description": "Set of parameters allowed on IP policy creation",
            "required": [
                "node",
                "neighbor"
            ],
            "allOf": [
                {
                    "oneOf": [
                        { "required": ["prefix"] },
                        { "required": ["asPath"] }
                    ]
                },
                {
                    "anyOf": [
                        { "required": ["priority"] },
                        { "required": ["med"] }
                    ]
                }
            ],
            "additionalProperties": false,
            "properties": {
                "node": {
                    "description": "Reference (nodeIndex) to the ingress node where the policy is defined",
                    "$ref": "node_v2.json#/definitions/node"
                },
                "neighbor": {
                    "description": "The neighbor node this policy applies to",
                    "$ref": "link_v2.json#/definitions/ipv4Reference"
                },
                "prefix": {
                    "description": "The prefix this policy applies to",
                    "$ref": "common.json#/definitions/ipv4Prefix"
                },
                "asPath": {
                    "description": "The AS path(s) this policy applies to",
                    "$ref": "#/definitions/asPath"
                },
                "priority": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 10
                },
                "med": {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 4294967295
                }
            }
        },

        "updateIPEPolicy": {
            "type": "object",
            "description": "Set of parameters allowed on IP policy update",
            "required": [
                "id"
            ],
            "anyOf": [
                { "required": ["priority"] },
                { "required": ["med"] }
            ],
            "additionalProperties": false,
            "properties": {
                "id": {
                    "description": "Program ID for the policy",
                    "$ref": "common.json#/definitions/index"
                },
                "node": {
                    "description": "Read-only, defined for convenience. If the value is different an error is returned",
                    "$ref": "node_v2.json#/definitions/node"
                },
                "neighbor": {
                    "description": "Read-only, defined for convenience. If the value is different an error is returned",
                    "$ref": "link_v2.json#/definitions/ipv4Reference"
                },
                "prefix": {
                    "description": "Read-only, defined for convenience. If the value is different an error is returned",
                    "$ref": "common.json#/definitions/ipv4Prefix"
                },
                "asPath": {
                    "description": "Read-only, defined for convenience. If the value is different an error is returned",
                    "$ref": "#/definitions/asPath"
                },
                "priority": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 10
                },
                "med": {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 4294967295
                }
            }
        },

        "deleteIPEPolicy": {
            "type": "object",
            "description": "Set of parameters allowed on IP policy update",
            "required": [
                "id"
            ],
            "additionalProperties": false,
            "properties": {
                "id": {
                    "description": "Program ID for the policy",
                    "$ref": "common.json#/definitions/index"
                }
            }
        },

        "bulkIPECreate" : {
            "type" : "array",
            "items" : {"$ref" : "#/definitions/createIPEPolicy"}
        },
        "bulkIPEUpdate" : {
            "type" : "array",
            "items" : {"$ref" : "#/definitions/updateIPEPolicy"}
        },
        "bulkIPEDelete" : {
            "type" : "array",
            "description" : "Only the id is used",
            "items" : {"$ref" : "#/definitions/deleteIPEPolicy"}
        }
    }
}
