{	
    "id" : "link.json",
    "$schema": "http://json-schema.org/draft-04/schema#",
    "$ref" : "#/definitions/link",
    "links" : [
	{
	    "title" : "get all links",
	    "href" : "/",
	    "method" : "GET",
	    "rel" : "instances",
	    "schema" : {"$ref" : "#/definitions/linkList"}
	},
	{
	    "title" : "get link based on filter",
	    "href" : "/search?name={nameFilter}&address={ipv4Address}&queryType=OR",
	    "method" : "GET",
	    "rel" : "search",
	    "schema" : {"$ref" : "#/definitions/linkList"}
	},
	{
	    "title" : "get a link",
	    "href" : "/{linkIndex}",
	    "method" : "GET",
	    "rel" : "self",
	    "schema" : {"$ref" : "#/definitions/link"}
	},
	{
	    "title" : "get a link event history",
	    "href" : "/{linkIndex}/history?start={startTimeStamp}&end={endTimeStamp}",
	    "description" : "Provide the history of events for the Link, it can be optionally filtered by start (inclusive) and end (exclusive) timestamp",
	    "method" : "GET",
	    "rel" : "self",
	    "schema" : {"$ref" : "#/definitions/linkHistoryEventList"}
	},
	{
	    "title" : "create a new link",
	    "description" : "Create a new link, schema on request is #/definitions/createLink",
	    "href" : "/",
	    "method" : "POST",
	    "rel" : "create",
	    "schema" : {
		"$ref" : "#/definitions/link",
		"required" : ["endA","endZ"]
	    }
	},
	{
	    "title" : "update a link",
	    "href" : "/{linkIndex}",
	    "description" : "Update an existing link, schema on request is #/definitions/updateLink",
	    "method" : "PUT",
	    "rel" : "self",
	    "schema" : {"$ref" : "#/definitions/link"}
	},
	{
	    "title" : "delete a link",
	    "href" : "/{linkIndex}",
	    "method" : "DELETE"
	}
    ],
    "definitions" : {
	"linkHistoryEventList" : {
	    "type" : "array",
	    "items" : { "$ref" : "#/definitions/linkHistoryEvent"}	    
	},
	"linkHistoryEvent" : {
	    "description" : "An entry in the history of an Link. The history consists of the information received from Topology acquisition",
            "type" :"object",
            "properties" : {
		"timestamp" : {
		    "description" :"Event Timestamp.",
		    "type" : "integer"
		}		
            },
	    "oneOf" : [
		{"$ref" :"#/definitions/link"}
            ]
	},
	"linkList" : {
	    "type" : "array",
	    "items" : {"$ref" : "#/definitions/link"}	    
	},
    "UndefinedInterface":{
      "id": "#/definitions/UndefinedInterface",
      "type" : "object",
      "description" : "Interface where correlation failed",
      "required":["interfaceIndex","address","topoObjectType"],
      "properties":{
		"topoObjectType" : {"type" : "string","enum" : ["UndefinedInterface"]},
        "interfaceIndex":{"type":"integer","enum" : [0]},
        "address" : {"type":"string"},
        "node" : {"$ref" : "node.json#/definitions/node"}
      }
    },
	"ipv4Reference" : {
	    "type" : "object",
	    "description" : "A numbered reference, not correlated to any object type",
	    "required" : ["address","topoObjectType"],
	    "properties" : {
		  "topoObjectType" : {"type" : "string","enum" : ["ipv4"]},
		  "address" : {"type":"string"},
          "linkIndex" : {"description" : "Optional attribute, refer to the link index","type" : "integer"}
	    }	    
	},
    "ipv4TaggedAddress" : {
	    "type" : "object",
	    "description" : "a numbered reference, not correlated to any object type, with an optional tag",
	    "required" : ["address","topoObjectType"],
        "additionalProperties" : false,
	    "properties" : {
          "topoObjectType" : {"type" : "string","enum" : ["ipv4"]},
	  	  "address" : {"type":"string","format" : "ipv4"},
          "tag" : {"type":"string"}
	    }
	},
    "hopIdReference" : {
        "type" : "object",
        "description" : "A link unique link reference using a globally unique link id",
        "required" : ["id","topoObjectType"],
        "properties" : {
          "topoObjectType" : {"type" : "string","enum" : ["hopId"]},
          "id" : {"type":"string"}
        }
    },
	"unnumberedIfReference" : {
	    "type" : "object",
	    "description" : "a unnumbered reference, not correlated to any object type",
	    "required" : ["node","topoObjectType","ifIndex"],
	    "properties" : {
		  "topoObjectType" : {"type" : "string","enum" : ["unnumberedIfId"]},
		  "node"    : {"type":"string"},
		  "ifIndex" : {"type":"integer"},
          "address"   : {"type":"string", "description" : "The Link name, if present"},
          "linkIndex" : {"description" : "Optional attribute, refer to the link index","type" : "integer"}
	    }	    
	},
	"interfaceSwCap" : {
	    "description" : "description of the interface type, based on transport topology",
	    "type" :"object",
	    "additionalProperties" : false,
	    "properties" :{
		"switchingCapability" : {
		    "enum": [
			"switching-packet",
			"switching-dcsc",
			"switching-otn",
			"switching-psc1",
			"switching-lsc",
			"switching-evpl",
			"switching-tdm",
			"switching-fsc",
			"switching-l2sc"
		    ],
		    "type": "string"
		},
		"encoding" : {
		    "enum": [
			"lsp-encoding-pdh",
			"lsp-encoding-optical-channel",
			"lsp-encoding-sdh",
			"lsp-encoding-packet",
			"lsp-encoding-digital-wrapper",
			"lsp-encoding-fiber",
			"lsp-encoding-line",
			"lsp-encoding-ethernet",
			"lsp-encoding-fiber-channel",
			"lsp-encoding-oduk",
			"lsp-encoding-lambda"
		    ],
		    "type": "string"
		}
	    }
	},
	"LinkInterfaceRef" : {
            "description" :"Reference to an interface on a link",
	    "type" : "object",
            "additionalProperties" : false,
	    "required" : ["topoObjectType"],
	    "properties" : {
		"linkName"       : {"type" : "string"},
		"topoObjectType" : {"type" : "string","enum" : ["interfaceRef"]},
		"ipv4Address" : {"description":"interface Ipv4 Address",
				 "$ref" : "#/definitions/ipv4Reference"},
                "ifIndex" : { 
                    "description" : "node local interface index",
                    "type" : "integer"
                },
		"node"    : { "$ref" : "node.json#/definitions/node"}
	    }
	},
        "SIDList" : {            
            "type" : "array",
            "items" : {"$ref" : "#/definitions/adjacencySegmentIdentifiers"}            
        },
        "adjacencySegmentIdentifiers" : {
            "type" : "object",
            "properties" :  {
                "weight" : {"type" : "number","description":""},
                "sid"    : {"type" : "number","description":""},
                "flags"  : {"type" : "number","description":"ISIS-Flags, the OSPF are mapped to the ISIS "}
            }
        },
        "interface" : {
            "description" :"interface, can be part of a link",
            "type" : "object",
            "additionalProperties" : false,
	    "required" : ["topoObjectType","node"],
            "properties" : {		
		"topoObjectType" : {"type" : "string","enum" : ["interface"]},
                "name"    : { "$ref" : "common.json#/definitions/name"},
                "interfaceIndex"   : { "$ref" : "common.json#/definitions/index"},
		"ipv4Address" : {"description":"interface Ipv4 Address",
				 "$ref" : "#/definitions/ipv4Reference"},
                "ifIndex" : { 
                    "description" : "node local interface index",
                    "type" : "integer"
                },
                "node"    : { "$ref" : "node.json#/definitions/node"},
                "TEmetric"    : {"description":"aggregated TE metric","type" : "integer"},
		"unreservedBw": {"description":"aggregated unreservedBw","$ref" : "common.json#/definitions/unreservedBw"},
		"interfaceSwitchingCapabilities" : {"description" : "description of the interface type", "$ref" : "#/definitions/interfaceSwCap"},
                "protocols": {
                    "description" : "Protocols configuration and information",
                    "type" : "object",
                    "additionalProperties" : false,
                    "properties" : {
                        "OSPF" : {
                            "type" : "object",
                            "additionalProperties" : false,
                            "properties" : {
                                "metric"   : {"type" : "integer"},
                                "TEMetric" : {"type" : "integer"},
                                "area"     : {"type" : "integer"},
				"srlgs"    : {"$ref" : "common.json#/definitions/srlgList"}
                            }
                        },								
                        "OSPFv3" : {
                            "type" : "object",
                            "additionalProperties" : false,
                            "properties" : {
                                "metric"   : {"type" : "integer"},
                                "TEMetric" : {"type" : "integer"},
                                "area"     : {"type" : "integer"},
				"srlgs"    : {"$ref" : "common.json#/definitions/srlgList"}

                            }
                        },                        
                        "ISIS": {
                            "type" : "object",
                            "additionalProperties" : false,
                            "properties" : {
                                "metric"   : {"type" : "integer"},
                                "TEMetric" : {"type" : "integer"},
                                "level"    : {"type" : "string", "enum" : ["L1","L2","L1L2"]},
				"srlgs"    : {"$ref" : "common.json#/definitions/srlgList"}
                            }								
                        },								
                        "RSVP": {
                            "type" : "object",
                            "additionalProperties" : false,
                            "properties" : {								
                                "bandwidth" : {"$ref" : "common.json#/definitions/Bandwidth" }
                            }
                        },
			"transport" : {
			    "type" : "object",
                            "additionalProperties" : false,
                            "properties" : {
				"clientReference" : {
                                    "$ref" : "#/definitions/ipv4Reference",
                                    "description" : "For Transport inter-layer link, this contains the IP address of the interface the access link is connected to. " 
                                },
                                "remoteLinkInfo" : {
				    "description" : "Transport inter-layer link that is connected to that link through the transport network. This information is calculated from connectivity matrix",
				    "$ref" : "#/definitions/LinkInterfaceRef"
				}
                            }
			},
                        "SR" : {
                            "type" : "object",
                            "description" : "SR properties",
                            "properties" : {
                                "SIDs" : {"$ref": "#/definitions/SIDList"}
                            }
                        },
                        "LDP" : {
                            "type" : "object",
                            "description" : "LDP protocol properties, placeholder",
                            "properties" : {}
                        }
                    }
                }, 
                "adminStatus" : {"$ref" : "common.json#/definitions/adminStatus"},		
                "bandwidth" : {"$ref" : "common.json#/definitions/Bandwidth"},
                "localProtection" : {
                    "description" : "MPLS local protection",
                    "type" : "string",					
                    "enum" : ["link","nodelink"]
                },
		"linkProtection" : {"$ref" : "#/definitions/linkProtectionType","description" : "Link protection, if derived from transport topology it does also set the canFail parameter to false"},
                "TEcolor" : {
                    "description" : "Coloring, Attributes, Affinity",
                    "type" : "integer"
                },					
                "delay" : {
                    "description" : "Link delay in millisecond",
                    "type" : "number"
                },
		"srlgs"    : {"$ref" : "common.json#/definitions/srlgList"},
                "designParameters" : {
                    "description" : "User defined design properties",
                    "type" : "object",
                    "properties" : {
                        "userCost":	{"type" : "integer","description" : "User metric"},
                        "canFail" :     {"type" : "boolean","default" : true,"description" : "Indicate if the link can fail or not. This parameter is evaluated when routing LSP with useProtectedLinks set to Protected."},
                        "distance" :    {"type" : "integer","description" : "link distance, unit:?"},
                        "trafficRerouteThreshold" : {"type" : "integer","description" : "the percentage of utilization that trigger a reroute based on analytics","minimum":0,"maximum":100}
                    }
                },
		"comment"           : {"description" : "Comment" , "type" : "string"},
                "interfaceName"     : {"description" : "interfaceName deduced from router configuration" , "type" : "string"},
                "userProperties" : {"$ref" : "userProperties.json#/definitions/linkInterfaceUserProperties"}
            }
        },
	"linkType" : {
	    "description" : "Summarized link type information.",
	    "type" : "string"	   	    
	},
	"linkProtectionType":  {
	    "description": "Link Protection Type desired for this link",
            "enum": [
                "unprotected",
                "extra-traffic",
                "shared",
                "1-for-1",
                "1-plus-1",
                "enhanced"
            ],
	    "type": "string"},
        "updateLink" : {
            "description" : "Set of properties that can be updated (PUT) on a link",
            "type" : "object",
	    "required" : ["topologyIndex","topoObjectType","linkIndex","endA","endZ"],
	    "additionalProperties" : false,
            "properties" : {
		"topoObjectType" : {"type" : "string","enum" : ["link"]},
		"topologyIndex" : { "$ref" : "topology.json#/definitions/topologyIndex"},
                "linkIndex" : {
                    "description" : "Program ID for link",
                    "type" : "integer"
                },
                "linkType" : {
                    "description" : "Link type",
                    "$ref" : "#/definitions/linkType"
                },
                "endA": {
                    "description": "Link information from A side",		    
                    "$ref"  :"link.json#/definitions/interface"
                },
                "endZ": {
                    "description": "Link information from Z side",
                    "$ref"  :"link.json#/definitions/interface"
		},
                "comment"           : {"description" : "Comment" , "type" : "string"}
	    }
        },
        "createLink" : {
            "description" : "Set of parameters accepts when creating (POST) a planned link",
            "type" : "object",
	    "required" : ["topologyIndex","topoObjectType","endA","endZ"],
	    "additionalProperties" : false,
            "properties" : {
		"topoObjectType" : {"type" : "string","enum" : ["link"]},
		"topologyIndex" : { "$ref" : "topology.json#/definitions/topologyIndex"},
                "linkType" : {
                    "description" : "Link type",
                    "$ref" : "#/definitions/linkType"
                },
                "endA": {		    
                    "description": "Link information from A side",
                    "$ref"  :"link.json#/definitions/interface"
                },
                "endZ": {
                    "description": "Link information from Z side",
                    "$ref"  :"link.json#/definitions/interface"                    		    
		},
                "comment"           : {"description" : "Comment" , "type" : "string"}
	    }
        },
        "link" : {
	    "description" : "Represents a single link",
	    "type" : "object",
	    "required" : ["topologyIndex","topoObjectType"],
            "properties" : {
		"topoObjectType" : {"type" : "string","enum" : ["link"]},
		"topologyIndex" : { "$ref" : "topology.json#/definitions/topologyIndex"},
                "name": {
                    "description": "Name of the link, generated by the NorthStar",
                    "$ref" : "common.json#/definitions/name255"},
                "linkIndex" : {
                    "description" : "Program ID for link",
                    "type" : "integer"
                },
                "linkType" : {
                    "description" : "Link type",
                     "$ref" : "#/definitions/linkType"
                },
		"serverLayerReference" : {
		    "description"  : "For Link that are supported by a path in a bidirectional server layer this attribute reference a LSP index that represent that path in the server layer, this is the reference to the lspIndex",
		    "type"         : "number" 
		}, 
		"operationalStatus" : {
		    "description" : "Link operational status",
		    "$ref" : "common.json#/definitions/operStatusAndPlanned"
		},
		"linkProtection" : {"$ref" : "#/definitions/linkProtectionType"},
                "endA": {
                    "description": "Link information from A side",
                    "$ref"  :"link.json#/definitions/interface"
                },
                "endZ": {
                    "description": "Link information from Z side",
                    "oneOf" : [
                        {"$ref"  :"link.json#/definitions/interface"},
                        {"$ref"  :"link.json#/definitions/UndefinedInterface"}
                    ]
                },
                "comment"           : {"description" : "Comment" , "type" : "string"}
        }
    }
}
}
