<?xml version="1.0"?>

<!-- 
Network Resource Model (NRM)
Copyright (C) 2009 Telematica Instituut

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

Contact information available at http://www.telin.nl/
Author: Arjan Peddemors
-->

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           xmlns="http://cosphere.telin.nl/nrm/nrm-types"
           targetNamespace="http://cosphere.telin.nl/nrm/nrm-types"
           elementFormDefault="qualified" 
           attributeFormDefault="unqualified">
  

  <!-- ================================================================== -->
  <!-- Identifier types. -->
  <!-- ================================================================== -->
  
  <xs:simpleType name="Id">
    <xs:restriction base="xs:unsignedInt"/>
  </xs:simpleType>
  
  <xs:simpleType name="TypeId">
    <xs:restriction base="xs:string"/>
  </xs:simpleType>
  
  <!-- ================================================================== -->
  <!-- Basic (abstract) types describing link layer functionality -->
  <!-- ================================================================== -->
  
  <!-- Link layer elements describe characteristics of functionality at the
  physical and link layer; deal with transferring bits and frames over one 
  or more links. Typically, these elements are network interface cards with 
  associating driver software or virtual network interfaces. If state is 0, 
  the link layer element is down, if 1 it is up. -->
  <xs:complexType name="LinkLayerElement" abstract="true">
    <xs:sequence>
      <xs:element name="linkLayerElementId" type="Id"/>
      <xs:element name="name" type="xs:string"/>
      <xs:element name="descr" type="xs:string"/>
      <xs:element name="state" type="xs:unsignedInt" default="0"/>
    </xs:sequence>
  </xs:complexType>
  
  <!-- A physical interface represents a hardware network interface (and
    associating driver software). Types deriving from this type must indicate 
    available links (derived from Link) that have a corresponding
    technology type, e.g. an IEEE 802.11 interface referring to IEEE 802.11
    links. -->
  <xs:complexType name="PhysicalInterface" abstract="true">
    <xs:complexContent>
      <xs:extension base="LinkLayerElement">
        <xs:sequence>
          <xs:element name="links">
            <xs:complexType>
              <xs:sequence>
                <!-- Reference to type (derived from) Link. -->
                <xs:element name="link" type="Id"
                  minOccurs="0" maxOccurs="unbounded"/>
              </xs:sequence>
            </xs:complexType>
          </xs:element>
        </xs:sequence>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>
  
  <!-- A virtual interface represents a logical element that can act as a
    link layer element but does not map directly to a hardware component.
    In most cases, a virtual interface uses another link layer element for
    the actual transfer of data. -->
  <xs:complexType name="VirtualInterface" abstract="true">
    <xs:complexContent>
      <xs:extension base="LinkLayerElement">
        <xs:sequence>
          <xs:element name="baseInterfaces">
            <xs:complexType>
              <xs:sequence>
                <!-- Reference to type (derived from) 
                  LinkLayerElement. -->
                <xs:element name="baseInterface" type="Id" 
                  minOccurs="0" maxOccurs="unbounded"/>
              </xs:sequence>
            </xs:complexType>
          </xs:element>
        </xs:sequence>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>
  
  <!-- Link layer data link, responsible for carrying bits and frames, and
  established by a link layer element (derived of LinkLayerElement). 
  When a link is active (state is 1), it can be used to setup a network layer
  path. A link can have multiple associated services; facilities supporting
  communication, not necessarily confined to the link layer (deriving from
  LinkService). -->
  <xs:complexType name="Link" abstract="true">
    <xs:sequence>
      <xs:element name="linkId" type="Id"/>
      <!-- Reference to type (derived from) LinkLayerElement -->
      <xs:element name="ifId" type="Id"/>
      <xs:element name="state" type="xs:unsignedInt" default="0"/>
      <xs:element name="services">
        <xs:complexType>
          <xs:sequence>
            <!-- Reference to type (derived from) LinkService -->
            <xs:element name="service" type="Id" 
              minOccurs="0" maxOccurs="unbounded"/>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
      <xs:element name="maxSpeed" type="xs:unsignedInt"/>
      <xs:element name="mtu" type="xs:unsignedInt"/>
    </xs:sequence>
  </xs:complexType>
  
  <!-- Service associated with a link layer link. Such a service could be
  a DNS server, proxy server, transcoding service, IP routing facility,
  etc. that is associated with a link, typically because it is only
  accessible through this link. Note that this service is not limited
  to link layer functionality. Information about the existence of this 
  service is obtained through such protocols as the Dynamic Host
  Configuration Protocol (DHCP). -->
  <xs:complexType name="LinkService" abstract="true">
    <xs:sequence>
      <xs:element name="linkServiceId" type="Id"/>
    </xs:sequence>
  </xs:complexType>
  
  
  <!-- ================================================================== -->
  <!-- Basic (abstract) types describing network layer functionality -->
  <!-- ================================================================== -->
  
  <!-- Network layer elements describe characteristics of functionality at 
  the network layer. They deal with paths (or routes) of network packets, 
  which by themselves are concatenated links. Types derived from this type 
  must indicate available paths (derived from Path) corresponding with
  their own type, e.g. an IPv4 stack referring to IPv4 paths. Without 
  additional parameterization, outgoing packets will be send over the 
  default path.-->
  <xs:complexType name="NetworkLayerElement" abstract="true">
    <xs:sequence>
      <xs:element name="networkLayerElementId" type="Id"/>
      <xs:element name="name" type="xs:string"/>
      <xs:element name="descr" type="xs:string"/>
      <xs:element name="routes">
        <xs:complexType>
          <xs:sequence>
            <!-- Reference to type (derived from) PathSegment. -->
            <xs:element name="route" type="Id"
              minOccurs="0" maxOccurs="unbounded"/>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
      <!-- Reference to type (derived from) PathSegment. -->
      <xs:element name="defaultRoute" type="Id" minOccurs="0"/>
    </xs:sequence>
  </xs:complexType>
  
  <!-- Network layer path segment, indicating one hop of a route taken by 
  network layer packets. A path segment always has a one-to-one mapping with 
  a link layer link (derived from Link). -->
  <xs:complexType name="PathSegment" abstract="true">
    <xs:sequence>
      <xs:element name="pathSegmentId" type="Id"/>
      <!-- Reference to type (derived from) Link. -->
      <xs:element name="link" type="Id"/>
    </xs:sequence>
  </xs:complexType>
  
  <!-- A local path segment can be used to establish routes to nodes
  available directly through the used link (nodes on the same local 
  network). A local path segment is - at one end - always attached to the 
  current host. -->
  <xs:complexType name="LocalPathSegment">
    <xs:complexContent>
      <xs:extension base="PathSegment">
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>
  
  <!-- A gateway path segment can be used to establish routes to nodes
  available directly through the used link as well as nodes that are more
  than one hop away. Paths to non-local nodes are established through the
  gateway. A gateway path segment is - at one end - always attached to the
  current host. -->
  <xs:complexType name="GatewayPathSegment">
    <xs:complexContent>
      <xs:extension base="PathSegment">
        <xs:sequence>
          <xs:element name="gateway" type="Id"/>
        </xs:sequence>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>
  
  
  <!-- ================================================================== -->
  <!-- Basic (abstract) types describing transport layer functionality -->
  <!-- ================================================================== -->
  
  <!-- Transport layer elements describe characteristics of functionality at 
  the transport layer. These elements deal with communication over end-to-end 
  connections (or channels, or pipes). The data over the end-to-end 
  connection travels through one or more network layer paths. Types derived 
  from this type must indicate existing transport layer links (derived from 
  Transport) corresponding with their own type, e.g. a TCP stack referring 
  to TCP connections. -->
  <xs:complexType name="TransportLayerElement" abstract="true">
    <xs:sequence>
      <xs:element name="transportLayerElementId" type="Id"/>
      <xs:element name="transports">
        <xs:complexType>
          <xs:sequence>
            <!-- Reference to type (derived from) Transport. -->
            <xs:element name="transport" type="Id"
              minOccurs="0" maxOccurs="unbounded"/>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
    </xs:sequence>
  </xs:complexType>
  
  <!-- Transport layer transport, responsible for end-to-end data 
  transmission. Types derived from this type must indicate which one or
  more paths (derived from PathSegment) are used for the connection. -->
  <xs:complexType name="Transport" abstract="true">
    <xs:sequence>
      <xs:element name="transportId" type="Id"/>
      <!-- Reference to type TransportLayerElement. -->
      <xs:element name="stack" type="Id"/>
    </xs:sequence>
  </xs:complexType>
  
  
  <!-- ================================================================== -->
  <!-- Specific (real) types describing link layer functionality -->
  <!-- ================================================================== -->
  
  <!-- Cellular interface. Multiple networks may be visible but only one
  can be active at a given time. This interface may support multiple modes
  (GPRS = 1, EDGE = 2, CDMA2000_RTT = 3, UMTS = 4) of which one is currently
  used. -->
  <xs:complexType name="CellularInterface">
    <xs:complexContent>
      <xs:extension base="PhysicalInterface">
        <xs:sequence>
          <xs:element name="currentMode" type="xs:unsignedInt"/>
          <xs:element name="supportedModes" maxOccurs="4">
            <xs:complexType>
              <xs:sequence>
                <xs:element name="supportedMode" type="xs:unsignedInt"/>
              </xs:sequence>
            </xs:complexType>
          </xs:element>
          <!-- Reference to type (derived from) CellularNetwork. -->
          <xs:element name="activeLink" type="Id" minOccurs="0"/>
        </xs:sequence>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>
  
  <!-- Cellular network base station. Indicates cell id, location area code, 
  and received signal strength indication. -->
  <xs:complexType name="BaseStation">
    <xs:sequence>
      <xs:element name="cid" type="xs:unsignedInt"/>
      <xs:element name="lac" type="xs:unsignedInt"/>
      <xs:element name="rssi" type="xs:int"/>
    </xs:sequence>
  </xs:complexType>
  
  <!-- Cellular network. The baseStation indicates currently used base 
  station and baseStationList indicates all detected base stations in 
  range for this operator. -->
  <xs:complexType name="CellularNetwork">
    <xs:complexContent>
      <xs:extension base="Link">
        <xs:sequence>
          <xs:element name="operatorName" type="xs:string"/>
          <xs:element name="operatorNumber" type="xs:unsignedInt"/>
          <xs:element name="baseStation" type="BaseStation"/>
          <xs:element name="baseStationList">
            <xs:complexType>
              <xs:sequence>
                <xs:element name="baseStation" type="BaseStation"
                  minOccurs="0" maxOccurs="unbounded"/>
              </xs:sequence>
            </xs:complexType>
          </xs:element>
        </xs:sequence>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>
  
  <!-- Interface representing IEEE 802.11 Wireless LAN physical and MAC 
  layer functionality. Multiple links (i.e. WLAN networks) may be accessible 
  through this interface, although only one may be active at a given time. 
  This interface may support multiple modes (802.11a = 1, 802.11b = 2, 
  802.11g = 3) of which one is currently used. -->
  <xs:complexType name="WLANInterface">
    <xs:complexContent>
      <xs:extension base="PhysicalInterface">
        <xs:sequence>
          <xs:element name="currentMode" type="xs:unsignedInt"></xs:element>
          <xs:element name="supportedModes">
            <xs:complexType>
              <xs:sequence>
                <xs:element name="supportedMode" type="xs:unsignedInt"
                  maxOccurs="3"/>
              </xs:sequence>
            </xs:complexType>
          </xs:element>
          <!-- Reference to type (derived from) WLANNetwork. -->
          <xs:element name="activeLink" type="Id" minOccurs="0"/>
        </xs:sequence>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>
  
  <!-- WLAN network access point. Indicates access point mac address (bssid), 
  and received signal strength indication (rssi). -->
  <xs:complexType name="AccessPoint">
    <xs:sequence>
      <xs:element name="bssid" type="xs:string"/>
      <xs:element name="rssi" type="xs:int"/>
    </xs:sequence>
  </xs:complexType>
  
  <!-- Representation of an IEEE 802.11 Wireless LAN network. -->
  <xs:complexType name="WLANNetwork">
    <xs:complexContent>
      <xs:extension base="Link">
        <xs:sequence>
          <xs:element name="ssid" type="xs:string"/>
          <xs:element name="accessPoint" type="AccessPoint"/>
          <xs:element name="accessPointList">
            <xs:complexType>
              <xs:sequence>
                <xs:element name="accessPoint" type="AccessPoint"
                  minOccurs="0" maxOccurs="unbounded"/>
              </xs:sequence>
            </xs:complexType>
          </xs:element>
        </xs:sequence>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>
  
  <!-- Bluetooth node. Indicates Bluetooth device address (BD_ADDR) and
    the user-friendly name. -->
  <xs:complexType name="BluetoothNode">
    <xs:sequence>
      <xs:element name="BD_ADDR" type="xs:string"/>
      <xs:element name="name" type="xs:string"/>
    </xs:sequence>
  </xs:complexType>
  
  <!-- Interface representing Bluetooth physical and link layer functionality.
  Multiple potential links to other Bluetooth nodes may be visible through 
  this interface and multiple links may be active. -->
  <xs:complexType name="BluetoothInterface">
    <xs:complexContent>
      <xs:extension base="PhysicalInterface">
        <xs:sequence>
          <!-- Local node info -->
          <xs:element name="localNode" type="BluetoothNode"/>
          <xs:element name="activeLinks">
            <xs:complexType>
              <xs:sequence>
                <!-- Reference to type (derived from) BluetoothLink. -->
                <xs:element name="link" type="Id"
                  minOccurs="0" maxOccurs="unbounded"/>
              </xs:sequence>
            </xs:complexType>
          </xs:element>
        </xs:sequence>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>
  
  <!-- Representation of a Bluetooth link with another Bluetooth node. 
  This link is not necessarily suitable for carrying IP traffic; it is 
  used to inform about in-range Bluetooth nodes. -->
  <xs:complexType name="BluetoothLink">
    <xs:complexContent>
      <xs:extension base="Link">
        <xs:sequence>
          <!-- Peer node. -->
          <xs:element name="node" type="BluetoothNode"/>
        </xs:sequence>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>

  <!-- Representation of a Bluetooth network based on the Bluetooth LAN 
  access profile. -->
  <xs:complexType name="BluetoothNetwork">
    <xs:complexContent>
      <xs:extension base="BluetoothLink"/>
    </xs:complexContent>
  </xs:complexType>
  
  <!-- Interface representing IEEE 802.3 Ethernet physical and MAC layer
    functionality. -->
  <xs:complexType name="EthernetInterface">
    <xs:complexContent>
      <xs:extension base="PhysicalInterface">
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>
  
  <!-- Representation of an IEEE 802.3 Ethernet network. -->
  <xs:complexType name="EthernetNetwork">
    <xs:complexContent>
      <xs:extension base="Link"/>
    </xs:complexContent>
  </xs:complexType>
  
  <!-- Serial interface -->
  <xs:complexType name="SerialInterface">
    <xs:complexContent>
      <xs:extension base="PhysicalInterface"/>
    </xs:complexContent>
  </xs:complexType>
  
  <!-- Serial network. -->
  <xs:complexType name="SerialNetwork">
    <xs:complexContent>
      <xs:extension base="Link"/>
    </xs:complexContent>
  </xs:complexType>
  
  <!-- The loopback interface allows (applications on) the host to transmit
  data to itself. Therefore, this virtual interface does not stack on top of 
  another interface. -->
  <xs:complexType name="LoopbackInterface">
    <xs:complexContent>
      <xs:extension base="VirtualInterface">
        <xs:sequence>
          <!-- Reference to type (derived from) LoopbackNetwork. -->
          <xs:element name="nwId" type="Id"></xs:element>
        </xs:sequence>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>
  
  <!-- Loopback network directly associated with loopback interface. -->
  <xs:complexType name="LoopbackNetwork">
    <xs:complexContent>
      <xs:extension base="Link"/>
    </xs:complexContent>
  </xs:complexType>
  
  <!-- Mobile IP virtual interface. -->
  <xs:complexType name="MIPInterface">
    <xs:complexContent>
      <xs:extension base="VirtualInterface">
        <xs:sequence>
          <xs:element name="tunnel" type="MIPTunnel" minOccurs="0"/>
        </xs:sequence>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>

  <!-- Mobile IP tunnel. -->
  <xs:complexType name="MIPTunnel">
    <xs:complexContent>
      <xs:extension base="Link">
        <xs:sequence>
          <xs:element name="pathSegment" type="GatewayPathSegment" 
            minOccurs="0"/>
        </xs:sequence>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>
  
  
  <!-- ================================================================== -->
  <!-- Specific (real) types describing network layer functionality -->
  <!-- ================================================================== -->
  
  <!-- Internet Protocol version 4 stack. Many more parameters may be defined
  here: see RFC 2011. -->
  <xs:complexType name="IPv4Stack">
    <xs:complexContent>
      <xs:extension base="NetworkLayerElement">
        <xs:sequence>
          <xs:element name="forwarding" type="xs:boolean"/>
          <xs:element name="defaultTTL" type="xs:unsignedByte"/>
        </xs:sequence>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>

  <!-- Internet Protocol version 4 local path segement. -->
  <xs:complexType name="IPv4LocalPathSegment">
    <xs:complexContent>
      <xs:extension base="LocalPathSegment">
        <xs:sequence>
          <xs:element name="address" type="xs:string"/>
          <xs:element name="net" type="xs:string"/>
          <xs:element name="prefix" type="xs:unsignedByte"/>
        </xs:sequence>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>

  <!-- Internet Protocol version 4 gateway path segement. -->
  <xs:complexType name="IPv4GatewayPathSegment">
    <xs:complexContent>
      <xs:extension base="GatewayPathSegment">
        <xs:sequence>
          <xs:element name="address" type="xs:string"/>
        </xs:sequence>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>
  
  <!-- Internet Protocol version 6 stack. -->
  <xs:complexType name="IPv6Stack">
    <xs:complexContent>
      <xs:extension base="NetworkLayerElement"/>
    </xs:complexContent>
  </xs:complexType>

  <!-- Internet Protocol version 6 local path segment. -->
  <xs:complexType name="IPv6LocalPathSegment">
    <xs:complexContent>
      <xs:extension base="LocalPathSegment"/>
    </xs:complexContent>
  </xs:complexType>

  <!-- Internet Protocol version 6 gateway path segment. -->
  <xs:complexType name="IPv6GatewayPathSegment">
    <xs:complexContent>
      <xs:extension base="GatewayPathSegment"/>
    </xs:complexContent>
  </xs:complexType>
  
  
  <!-- ================================================================== -->
  <!-- Specific (real) types describing transport layer functionality -->
  <!-- ================================================================== -->
  
  <!-- User Datagram Protocol stack. Responsible for sending and receiving
  UDP packets. Many (statistical) parameters possible: see RFC 4113. -->
  <xs:complexType name="UDPStack">
    <xs:complexContent>
      <xs:extension base="TransportLayerElement">
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>
  
  <!-- User Datagram Protocol listener.  Receives incoming packets for a
  certain port number. The localPathsSegment is 0 when not bound to a 
  specific IP number. -->
  <xs:complexType name="UDPListener">
    <xs:complexContent>
      <xs:extension base="Transport">
        <xs:sequence>
          <!-- Reference to type LocalPathSegment. -->
          <xs:element name="localPathSegment" type="Id"/>
          <xs:element name="port" type="xs:unsignedShort"/>
        </xs:sequence>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>
  
  <!-- Transmission Control Protocol stack. Responsible for creating, 
  maintaining, and terminating TCP connections. Many (statistical)
  parameters possible: see RFC 2012. -->
  <xs:complexType name="TCPStack">
    <xs:complexContent>
      <xs:extension base="TransportLayerElement">
        <xs:sequence>
          <xs:element name="maxConnections" type="xs:unsignedInt"/>
        </xs:sequence>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>
  
  <!-- Transmission Control Protocol listener.  Waits for connection 
  establishment on a certain port number. The localPathsSegment is 0 when 
  not bound to a specific IP number. -->
  <xs:complexType name="TCPListener">
    <xs:complexContent>
      <xs:extension base="Transport">
        <xs:sequence>
          <!-- Reference to type LocalPathSegment. -->
          <xs:element name="localPathSegment" type="Id"/>
          <xs:element name="port" type="xs:unsignedShort"/>
        </xs:sequence>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>
  
  <!-- Transmission Control Protocol connection. A TCP connection uses one 
  path for incoming / outgoing packets.  State indicates the local socket 
  TCP state (CLOSED, SYN_SENT, ESTABLISHED, CLOSE_WAIT, etc.). -->
  <xs:complexType name="TCPConnection">
    <xs:complexContent>
      <xs:extension base="Transport">
        <xs:sequence>
          <!-- Reference to type PathSegment. -->
          <xs:element name="pathSegment" type="Id"/>
          <xs:element name="localPort" type="xs:unsignedShort"/>
          <xs:element name="remoteAddress" type="xs:string"/>
          <xs:element name="remotePort" type="xs:unsignedShort"/>
          <xs:element name="state" type="xs:unsignedInt"/>
        </xs:sequence>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>
  
  <!-- Stream Control Transmission Protocol stack. Responsible for creating, 
  maintaining, and terminating SCTP associations/connections. -->
  <xs:complexType name="SCTPStack">
    <xs:complexContent>
      <xs:extension base="TransportLayerElement">
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>
  
  <!-- Stream Control Transmission Protocol listener. Waits for connection 
  establishment on a certain port number. The localPathsSegment is 0 when 
  not bound to a specific IP number.-->
  <xs:complexType name="SCTPListener">
    <xs:complexContent>
      <xs:extension base="Transport">
        <xs:sequence>
          <!-- Reference to type LocalPathSegment. -->
          <xs:element name="localPathSegment" type="Id"/>
          <xs:element name="port" type="xs:unsignedShort"/>
        </xs:sequence>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>
  
  <!-- Stream Control Transmission Protocol association. An SCTP connection 
  uses one or more paths for incoming / outgoing packets. State indicates 
  the local socket SCTP state (CLOSED, COOKIE_WAIT, ESTABLISHED, 
  SHUTDOWN_PENDING, etc.).-->
  <xs:complexType name="SCTPAssociation">
    <xs:complexContent>
      <xs:extension base="Transport">
        <xs:sequence>
          <xs:element name="pathSegments" type="Id">
            <xs:complexType>
              <xs:sequence>
                <!-- Reference to type PathSegment. -->
                <xs:element name="pathSegment" type="Id"
                  minOccurs="1" maxOccurs="65536"/>
              </xs:sequence>
            </xs:complexType>
          </xs:element>
          <xs:element name="localPort" type="xs:unsignedShort"/>
          <xs:element name="remoteAddresses">
            <xs:complexType>
              <xs:element name="remoteAddress" type="xs:string"
                minOccurs="1" maxOccurs="65536"/>
            </xs:complexType>
          </xs:element>
          <xs:element name="remotePort" type="xs:unsignedShort"/>
          <xs:element name="state" type="xs:unsignedInt"/>
        </xs:sequence>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>
  

  <!-- ================================================================== -->
  <!-- Link associated services (DNS, proxies, gateways, etc.). -->
  <!-- ================================================================== -->
  
  <!-- Domain Name System service. When defaultResolver is true, this DNS
  server is used to query the DNS. -->
  <xs:complexType name="DNSServer">
    <xs:complexContent>
      <xs:extension base="LinkService">
        <xs:sequence>
          <xs:element name="address" type="xs:string"/>
          <xs:element name="defaultResolver" type="xs:boolean"/>
        </xs:sequence>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>
  
  <!-- IP Gateway. -->
  <xs:complexType name="Gateway">
    <xs:complexContent>
      <xs:extension base="LinkService">
        <xs:sequence>
          <xs:element name="address" type="xs:string"/>
        </xs:sequence>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>
  
  
  <!-- ================================================================== -->
  <!-- Session definition (client-server) -->
  <!-- ================================================================== -->
  
  <xs:complexType name="Msg">
  </xs:complexType>
  
  <xs:complexType name="Instance">
    <xs:complexContent>
      <xs:extension base="Msg">
        <xs:choice>
          <xs:element name="CellularInterface" type="CellularInterface"/>
          <xs:element name="CellularNetwork" type="CellularNetwork"/>
          <xs:element name="WLANInterface" type="WLANInterface"/>
          <xs:element name="WLANNetwork" type="WLANNetwork"/>
          <xs:element name="BluetoothInterface" type="BluetoothInterface"/>
          <xs:element name="BluetoothNetwork" type="BluetoothNetwork"/>
          <xs:element name="BluetoothLink" type="BluetoothLink"/>
          <xs:element name="EthernetInterface" type="EthernetInterface"/>
          <xs:element name="EthernetNetwork" type="EthernetNetwork"/>
          <xs:element name="SerialInterface" type="SerialInterface"/>
          <xs:element name="SerialNetwork" type="SerialNetwork"/>
          <xs:element name="LoopbackInterface" type="LoopbackInterface"/>
          <xs:element name="LoopbackNetwork" type="LoopbackNetwork"/>
          <xs:element name="MIPInterface" type="MIPInterface"/>
          <xs:element name="IPv4Stack" type="IPv4Stack"/>
          <xs:element name="IPv6Stack" type="IPv6Stack"/>
          <xs:element name="IPv4LocalPathSegment" type="IPv4LocalPathSegment"/>
          <xs:element name="IPv4GatewayPathSegment" type="IPv4GatewayPathSegment"/>
          <xs:element name="IPv6LocalPathSegment" type="IPv6LocalPathSegment"/>
          <xs:element name="IPv6GatewayPathSegment" type="IPv6GatewayPathSegment"/>
          <xs:element name="UDPStack" type="UDPStack"/>
          <xs:element name="TCPStack" type="TCPStack"/>
          <xs:element name="SCTPStack" type="SCTPStack"/>
          <xs:element name="UDPListener" type="UDPListener"/>
          <xs:element name="TCPListener" type="TCPListener"/>
          <xs:element name="TCPConnection" type="TCPConnection"/>
          <xs:element name="SCTPListener" type="SCTPListener"/>
          <xs:element name="SCTPConnection" type="SCTPConnection"/>
          <xs:element name="DNSServer" type="DNSServer"/>
          <xs:element name="Gateway" type="Gateway"/>
        </xs:choice>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>
  
  <xs:complexType name="InstanceId">
    <xs:complexContent>
      <xs:extension base="Msg">
        <xs:sequence>
          <xs:element name="type" type="xs:string"></xs:element>
          <xs:element name="id" type="Id"></xs:element>
        </xs:sequence>    
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>
  
  
  <xs:complexType name="MsgTransBegin">
    <xs:complexContent>
      <xs:extension base="Msg"/>
    </xs:complexContent>
  </xs:complexType>
  
  <xs:complexType name="MsgTransEnd">
    <xs:complexContent>
      <xs:extension base="Msg"/>
    </xs:complexContent>
  </xs:complexType>
  
  <xs:complexType name="MsgCreate">
    <xs:complexContent>
      <xs:extension base="Instance"/>
    </xs:complexContent>
  </xs:complexType>
  
  <xs:complexType name="MsgUpdate">
    <xs:complexContent>
      <xs:extension base="Instance"/>
    </xs:complexContent>
  </xs:complexType>
  
  <xs:complexType name="MsgDelete">
    <xs:complexContent>
      <xs:extension base="InstanceId"/>
    </xs:complexContent>
  </xs:complexType>
  
  <xs:complexType name="MsgSubscribe">
    <xs:complexContent>
      <xs:extension base="Msg">
        <xs:choice maxOccurs="unbounded">
          <xs:element name="layer">
            <xs:simpleType>
              <xs:restriction base="xs:string">
                <xs:enumeration value="transport"/>
                <xs:enumeration value="network"/>
                <xs:enumeration value="link"/>
              </xs:restriction>
            </xs:simpleType>
          </xs:element>
          <xs:element name="type" type="TypeId"/>
          <xs:element name="instance">
            <xs:complexType>
              <xs:sequence>
                <xs:element name="type" type="TypeId"/>
                <xs:element name="id" type="Id"/>
              </xs:sequence>
            </xs:complexType>
          </xs:element>
        </xs:choice>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>
  
  <xs:complexType name="MsgIoctlCall">
    <xs:complexContent>
      <xs:extension base="Msg">
        <xs:sequence>
          <xs:element name="callid" type="xs:unsignedInt"/>
          <xs:element name="type" type="TypeId"/>
          <xs:element name="id" type="Id"/>
          <xs:element name="ioctl" type="xs:unsignedInt"/>
          <xs:element name="input" type="xs:hexBinary"/>
        </xs:sequence>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>
  
  <xs:complexType name="MsgIoctlResult">
    <xs:complexContent>
      <xs:extension base="Msg">
        <xs:sequence>
          <xs:element name="callid" type="xs:unsignedInt"/>
          <xs:element name="result" type="xs:boolean"/>
          <xs:element name="output" type="xs:hexBinary"/>
        </xs:sequence>
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>
  
  <!-- A client-server session uses messages for interaction. Typically, the
  following interaction takes place: 1) session is established, 2) client
  indicates interest in receiving notifications from server by sending a
  subscribe message, 3) server sends notifications on current state using 
  create, updated, delete messages. The key and keyref definitions ensure 
  existence and uniqueness of the various identifiers, and enforce that 
  referenced elements exist. Changes (create, update, delete) always take
  place in a transaction context, i.e. a series of notifications are
  preceded by a TransBegin message and succeeded by a TransEnd message. -->
  <xs:element name="session">
    <xs:complexType>
      <xs:choice minOccurs="0" maxOccurs="unbounded">
        <xs:element name="MsgTransBegin" type="MsgTransBegin"/>
        <xs:element name="MsgTransEnd" type="MsgTransEnd"/>
        <xs:element name="MsgCreate" type="MsgCreate"/>
        <xs:element name="MsgUpdate" type="MsgUpdate"/>
        <xs:element name="MsgDelete" type="MsgDelete"/>
        <xs:element name="MsgSubscribe" type="MsgSubscribe"/>
        <xs:element name="MsgIoctlCall" type="MsgIoctlCall"/>
        <xs:element name="MsgIoctlResult" type="MsgIoctlResult"/>
      </xs:choice>
    </xs:complexType>
    
    <xs:key name="linkLayerElementKey">
      <xs:selector xpath="*/*"/>
      <xs:field xpath="@linkLayerElementId"/>
    </xs:key>
    <xs:keyref refer="linkLayerElementKey" name="linkLayerElementKeyRef1">
      <xs:selector xpath="*/*/baseInterfaces"></xs:selector>
      <xs:field xpath="baseInterface"></xs:field>
    </xs:keyref>
    <xs:keyref refer="linkLayerElementKey" name="linkLayerElementKeyRef2">
      <xs:selector xpath="*/*"></xs:selector>
      <xs:field xpath="ifId"></xs:field>
    </xs:keyref>
    
    <xs:key name="linkKey">
      <xs:selector xpath="*/*"></xs:selector>
      <xs:field xpath="@linkId"></xs:field>
    </xs:key>
    <xs:keyref refer="linkKey" name="linkKeyRef1">
      <xs:selector xpath="*/*/links"></xs:selector>
      <xs:field xpath="link"></xs:field>
    </xs:keyref>
    <xs:keyref refer="linkKey" name="linkKeyRef2">
      <xs:selector xpath="*/*"></xs:selector>
      <xs:field xpath="link"></xs:field>
    </xs:keyref>
    
    <xs:key name="linkServiceKey">
      <xs:selector xpath="*/*"/>
      <xs:field xpath="@linkServiceId"/>
    </xs:key>
    <xs:keyref refer="linkServiceKey" name="linkServiceKeyRef">
      <xs:selector xpath="*/*/services"></xs:selector>
      <xs:field xpath="service"></xs:field>
    </xs:keyref>
    
    <xs:key name="networkLayerElementKey">
      <xs:selector xpath="networkLayerElements/*"/>
      <xs:field xpath="@networkLayerElementId"/>
    </xs:key>
    
    <xs:key name="pathSegmentKey">
      <xs:selector xpath="*/*"/>
      <xs:field xpath="@pathSegmentId"/>
    </xs:key>
    <xs:keyref refer="pathSegmentKey" name="pathSegmentKeyRef1">
      <xs:selector xpath="*/*/routes"></xs:selector>
      <xs:field xpath="route"></xs:field>
    </xs:keyref>
    <xs:keyref refer="pathSegmentKey" name="pathSegmentKeyRef2">
      <xs:selector xpath="*/*"></xs:selector>
      <xs:field xpath="defaultRoute"></xs:field>
    </xs:keyref>
    <xs:keyref refer="pathSegmentKey" name="pathSegmentKeyRef3">
      <xs:selector xpath="*/*"></xs:selector>
      <xs:field xpath="localPathSegment"></xs:field>
    </xs:keyref>
    <xs:keyref refer="pathSegmentKey" name="pathSegmentKeyRef4">
      <xs:selector xpath="*/*"></xs:selector>
      <xs:field xpath="pathSegment"></xs:field>
    </xs:keyref>
    <xs:keyref refer="pathSegmentKey" name="pathSegmentKeyRef5">
      <xs:selector xpath="*/*/pathSegments"></xs:selector>
      <xs:field xpath="pathSegment"></xs:field>
    </xs:keyref>
    
    <xs:key name="transportLayerElementKey">
      <xs:selector xpath="transportLayerElements/*"/>
      <xs:field xpath="@transportLayerElementId"/>
    </xs:key>
    
    <xs:key name="transportKey">
      <xs:selector xpath="*/*"/>
      <xs:field xpath="@transportId"/>
    </xs:key>
    <xs:keyref refer="transportKey" name="transportKeyRef">
      <xs:selector xpath="*/*/transports"></xs:selector>
      <xs:field xpath="transport"></xs:field>
    </xs:keyref>
    
  </xs:element>  
</xs:schema>
