{
    "id" : "rpcs.json",
    "title" : "NorhtStar RPCs",
    "$schema": "http://json-schema.org/draft-04/schema#",
    "links" : [
        {
            "title" : "Network optimization RPC",
	    "description" : "Trigger Network optimization, either global or targeted to specific elements",
	    "href" : "/optimize",
	    "method" : "POST",
	    "targetSchema" : {
		"$ref" : "#/definitions/optimizationResponse"
	    },
            "schema" : {
                "$ref" : "#/definitions/networkOptimizationRequest"
            }
        },
        {
            "title" : "RPC",
	    "description" : "Get network optimization results",
	    "href" : "/optimize",
	    "method" : "GET",
	    "targetSchema" : {
		"$ref" : "#/definitions/optimizationStatus"
	    }
        },
        {
            "title" : "Failure Simulation RPC",
	    "description" : "Trigger Network Simulation",
	    "href" : "/simulation",
	    "method" : "POST",
	    "schema" : {
		"$ref" : "#/definitions/simulationRequest"
	    },
            "targetSchema" : {
                "$ref" : "#/definitions/simulationResponse"
            }
        },
        {
            "title" : "GET Simulation RPC list",
	    "href" : "/simulation",
	    "method" : "GET",
            "schema" : {
		"$ref" : "#/definitions/simulationsList"
	    }
        },
        {
            "title" : "GET a list of simulation reports of one simulation",
	    "href" : "/simulation/{uuid}",
	    "method" : "GET",
            "schema" : {
		"$ref" : "#/definitions/simulationReports"
	    }
        },
        {
            "title" : "GET Simulation report of one simulation",
	    "href" : "/simulation/{uuid}/{report}",
	    "method" : "GET"
        },
        {
            "title" : "Delete a simulation result",
	    "href" : "/simulation/{uuid}",
	    "method" : "DELETE"
        },
        {
            "title" : "Failure P2MP Diverse Tree Design optimization RPC",
	    "description" : "P2MP Diverse Tree Design optimization",
	    "href" : "/diverseTreeDesign",
	    "method" : "POST",
	    "schema" : {
		"$ref" : "#/definitions/diverseTreeRequest"
	    },
            "targetSchema" : {
                "$ref" : "#/definitions/diverseTreeResult"
            }
        },
        {
            "title" : "GET Simulation optimization RPC list",
	    "href" : "/diverseTreeDesign",
	    "method" : "GET",
            "schema" : {
		"$ref" : "#/definitions/diverseTreeResultList"
	    }
        },
        {
            "title" : "GET P2MP Diverse Tree Design report",
	    "href" : "/diverseTreeDesign/{uuid}",
	    "method" : "GET",
            "schema" : {
		"$ref" : "#/definitions/diverseTreeResult"
	    }
        },
        {
            "title" : "Delete P2MP Diverse Tree Design result",
	    "href" : "/diverseTreeDesign/{uuid}",
	    "method" : "DELETE"
        }
    ],
    "definitions" : {
        "networkOptimizationRequest" : {
            "type" : "object",
            "description" : "Payload for optimizing specific elements in the network",
            "properties" : {
                "elements" : {
                    "type" : "array",
	            "items" : {"$ref" : "#/definitions/optimizationElement"}
                }
            }
        },
        "optimizationElement" : {
            "type" : "object",
            "description" : "element to be optimized, similar to maintenanceElement",
	    "required" : ["index","topoObjectType"],
	    "properties": {
                "index" : {"description":"The index of the link, lsp, depending on the type.", "$ref" : "common.json#/definitions/index" },
		"topoObjectType" : {"type" : "string", "enum":["lsp","link"]}
	    }
        },
        "optimizationResponse" : {
            "oneOf" : [
                {"type" : "object", "required" : ["result"],"properties" : {"result" : {"type" : "string"}}},
                {"$ref" : "#/definitions/networkOptimizationRequest", "description" : "on response, the optimized elements"}
            ]},
        "networkOptimizationMetrics" : {
            "type" : "object",
            "properties" : {
                "bandwidth": {"type" : "number","description" : "Total bandwidth used"},
                "hopCount": {"type" : "number","description" : "Max/total hop count" },
                "latency": {"type" : "number","description" : "Max ? Total latency" }
            }
        },
        "optimizationStatus"   : {
            "type" : "object",
            "properties" : {
                "previous" : {"description" : "Previous network state metrics", "$ref" : "#/definitions/networkOptimizationMetrics"},
                "optimized": {"description" : "New network state metrics",      "$ref" : "#/definitions/networkOptimizationMetrics"},
                "numberOfOptimizedPaths"   : {"type" : "number","description" : "Number of optimized Tunnels" } ,
                "maxHopCount"              : {"type" : "number","description" : "Max number of hops" } ,
                "maxLatency"               : {"type" : "number","description" : "Max tunnel latency" } ,
                "tunnelCount"              : {"type" : "number","description" : "Number of tunnels" } ,
                "lastOptimizationTimeStamp": {"type" : "string","format" : "date-time" }
            }
        },
        "simulationElement" : {
            "oneOf" : [
                {

                    "type" : "string",
                    "enum" : [
                        "node","link","parallelLink","site","srlg","card","slot"
                    ]
                },
                {
                    "type" : "object",
                    "description" : "Indicate a maintenance event to be simulated, only one maintenance per simulation can be requested (the last one) ",
                    "required" : ["type","maintenanceName"],
                    "properties" : {
                        "type" : {
                            "type" : "string",
                            "enum" : ["maintenance"]
                        },
                        "maintenanceName" : {"type" : "string"}
                    }
                }
            ]
        },
        "simulationRequest"    : {
            "type" : "object",
            "properties" : {
                "topologyIndex" : {"$ref" : "topology.json#/definitions/topologyIndex"},
	        "elements"      : {
                    "type"        : "array",
                    "description" : "list of  elements kind that will be failed during the simulation",
                    "items": { "$ref" : "#/definitions/simulationElement"}
                },
                "detailedReport" : {
                    "type" : "boolean","default" :true,"desciption" : "generate detailed report"
                },
                "startTime" : {"$ref" :"common.json#/definitions/dateTime","description" : "Permanent element and LSPs active after startTime will be included"},
                "endTime"   : {"$ref" :"common.json#/definitions/dateTime","description" : "Permanent element and LSPs active before endTime will be included"}
            }
        },
        "simulationResponse"   : {
            "type" : "object",
            "properties" : {
                "topologyIndex" : {"$ref" : "topology.json#/definitions/topologyIndex"},
	        "elements"      : {
                    "type"        : "array",
                    "description" : "list of  elements kind that will be failed during the simulation",
                    "items": { "$ref" : "#/definitions/simulationElement"}
                },
                "detailedReport" : {
                    "type" : "boolean","default" :true,"desciption" : "generate detailed report"
                },
                "startTime" : {"$ref" :"common.json#/definitions/dateTime","description" : "Permanent element and LSPs active after startTime will be included"},
                "endTime"   : {"$ref" :"common.json#/definitions/dateTime","description" : "Permanent element and LSPs active before endTime will be included"},
                "status" : {
                    "type" : "string",
                    "enum" : ["failed","partial","success"],
                    "description" : "Indicates if the failure simulation request was successfull"
                },
                "message" : {"type" : "string"},
                "timestamp" : {"type":"string","description" : "UTC timestamp of the request creation."},
                "simulationId": {
                    "type" : "string",
                    "description" : "Each call the the failure simulation API will result into a new simulation beeing run. Each Simulation results can be accessed in the link described in results and will be retained for one day before beeing purged"
                },
                "results" : {
                    "type" : "object",
                    "properties" : {
                        "links": {"$ref" :"common.json#/definitions/APILinkList"}
                    }
                }

            }
        },
        "simulationsList"   : {
            "type" : "object",
            "properties" : {
                "topologyIndex" : {"$ref" : "topology.json#/definitions/topologyIndex"},
	        "simulationReports" : {
                    "type" :"array",
                    "items" : {
                        "description" : "Each call the the failure simulation API will result into a new simulation beeing run. Each Simulation results can be accessed in the link described in results and will be retained for one day before beeing purged",
                        "$ref" : "#/definitions/simulationResponse"
                    }
                }
            }
        },
        "simulationsReportLink" : {
            "type" : "object",
            "properties" : {
                "reportName": {"type" : "string","description" : " the report name" },
                "links"     : {"$ref" :"common.json#/definitions/APILinkList"}
            }
        },
        "simulationReports" : {
            "type" : "object",
            "description": "list of reports generated by the simulation, each report is a text file",
            "properties" : {
                "topologyIndex" : {"$ref" : "topology.json#/definitions/topologyIndex"},
	        "elements"      : {
                    "type"        : "array",
                    "description" : "list of  elements kind that will be failed during the simulation",
                    "items": { "$ref" : "#/definitions/simulationElement"}
                },
                "detailedReport" : {
                    "type" : "boolean","default" :true,"desciption" : "generate detailed report"
                },
                "startTime" : {"$ref" :"common.json#/definitions/dateTime","description" : "Permanent element and LSPs active after startTime will be included"},
                "endTime"   : {"$ref" :"common.json#/definitions/dateTime","description" : "Permanent element and LSPs active before endTime will be included"},
                "simulationId": {
                    "type" : "string",
                    "description" : "Each call the the failure simulation API will result into a new simulation beeing run. Each Simulation results can be accessed in the link described in results and will be retained for one day before beeing purged"
                },
                "status" : {
                    "type" : "string",
                    "enum" : ["failed","partial","success"],
                    "description" : "Indicates if the failure simulation request was successfull"
                },
                "message" : {"type" : "string"},
                "reports": {
                    "type" : "array",
                    "items" : { "$ref" : "#/definitions/simulationsReportLink"}
                }
            }
        },
        "diverseTreeRequest"  : {
            "type" : "object",
            "description": "Trigger P2MP Diverse tree design. The design is done at the networkTime if any, Both Tree BW calendaring is ignored (trees as considered as permanent) during the tree design ",
            "properties" : {
                "P2MPGroup"        :  {
                    "oneOf" : [
                        { "$ref" : "p2mp.json#/definitions/p2mpGroupReference","description" : "Id of the second P2MP group to optimize"},                       
                        { "$ref" : "p2mp.json#/definitions/createP2mpGroup","description" : "First New P2MP group, if the design is successfull AND useResultAsEro is set, then the group will be created" }
                    ]},
                "diverseP2MPGroup" :  {
                    "oneOf" : [
                        { "$ref" : "p2mp.json#/definitions/p2mpGroupReference","description" : "Id of the first P2MP group to optimize" },
                        { "$ref" : "p2mp.json#/definitions/createP2mpGroup","description" : "Second new P2MP group, if the design is successfull AND useResultAsEro is set, then the group will be created" }
                    ]},
                "ignoreExistingPath" : {"type" : "boolean" , "description" : "If set to true, any existing ero/required path is discarded for the design"},
                "useResultAsEro"     : {"type" : "boolean" , "description" : "If set to true, use the optimization result as required path"},
                "maxIterations"      : {"type" : "number" ,"minimum" : 1, "description" : "Number of iteration for the simulated annealing algorithm"},
                "sites"              : {
                    "description" : "Site pairing ",
                    "type" : "array",
                    "items" : {
                        "type" : "object",
                        "description" : "One Site definition",
                        "required" : ["site","nodes"],
                        "properties" : {
                            "site" : {"type" : "string","description" :"Site name","minLength" : 1},
                            "nodes": {
                                "type" : "array",
                                "items" : { "type" : "object","required" : ["nodeIndex"], "properties" : { "nodeIndex": {  "description": "Program ID for node","$ref" : "common.json#/definitions/index"}}}
                            }
                        }
                    }
                },
                "networkTime" : {"$ref" :"common.json#/definitions/dateTime","description" : "Do the optimization at that network time"},
                "creationConfigurationMethod" : {"description" : "This is the SouthBound protocol/interface used by NorthStar to create the LSP." , "type" : "string","enum":["PCEP","NETCONF"],"default":"NETCONF"}
            }
        },
        "diverseTreeResult" : {
            "type" : "object",
            "description": "Result of a p2mpTree optimization",
            "properties" : {
                "request" : { "$ref" : "#/definitions/diverseTreeRequest","description" : "Request parameters" },
                "result"  : { "$ref" : "#/definitions/diverseTreeState","description" : "result of the optimization" }
            }
        },
        "diverseTreeResultList"     : {
            "type" : "object",
            "properties" : {
                "topologyIndex" : {"$ref" : "topology.json#/definitions/topologyIndex"},
	        "rpcRequestIdList" : {
                    "type" :"array",
                    "items" : {
                        "type" : "string",
                        "description" : "Each call the the failure simulation API will result into a new simulation beeing run. Each Simulation results can be accessed in the link described in results and will be retained for one day before beeing purged"
                    }
                }
            }
        },
        "diverseTreeState"    : {
            "type" : "object",
            "description": "State of a p2mpTree optimization.",
            "required" : ["requestId","status"],
            "properties" : {
                "requestId"     : {
                    "type" : "string",
                    "description" : "Each call the the diverse tree design  API will result into a new design beeing run. Each call will create a new id, results are kept for 1 day"},
                "status"        : {"type" : "string","enum" : ["running","success","partial", "failed"],"description" : "design status"},
                "maxIterations" : {"type" : "number" ,"minimum" : 1, "description" : "Number of iteration for the simulated annealing algorithm"},
                "iterationsRun" : {"type" : "number" , "description" : "Current number of iteration ran by the algorithm"},
                "P2MPGroup"        : {"$ref" : "p2mp.json#/definitions/p2mpGroup","description" : "When the design is finished and results are available, this contains the full P2MP tree result"},
                "diverseP2MPGroup" : {"$ref" : "p2mp.json#/definitions/p2mpGroup","description" : "When the design is finished  and results are available, this contains the full P2MP tree result"}
            }
        }
    }

}
