alto

package module
v0.0.0-...-6c71341 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 1, 2014 License: BSD-2-Clause Imports: 5 Imported by: 0

README

Package alto implements JSON encoder and decoder for the Application-Layer Traffic Optimization (ALTO) protocol as described in http://tools.ietf.org/html/draft-ietf-alto-protocol.

GoDoc Build Status

Documentation

Overview

Package alto implements JSON encoder and decoder for the Application-Layer Traffic Optimization (ALTO) protocol as described in http://tools.ietf.org/html/draft-ietf-alto-protocol.

Encoding at server side:

accepts := req.Header.Get("Accept")
if accepts == "" {
	// error handling
}
if !strings.Contains(accepts, alto.MediaTypeDirectory) {
	// error handling
}
w.Header().Set("Content-Type", alto.MediaTypeDirectory)
var dir alto.Directory
if err := json.NewEncoder(w).Encode(&dir); err != nil {
	// error handling
}

Decoding at client side:

client := &http.Client{}
req, err := http.NewRequest("GET", "http://...", nil)
if err != nil {
	// error handling
}
req.Header.Set("Accept", alto.MediaTypeNetworkMap+","+alto.MediaTypeError)
resp, err := client.Do(req)
if err != nil {
	// error handling
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
	// error handling
}
nmap := alto.NewResource("networkmap")
if err := json.NewDecoder(resp.Body).Decode(nmap); err != nil {
	// error handling
}

Index

Constants

View Source
const (
	MediaTypeCostMap       = "application/alto-costmap+json"       // media type for ALTO map service
	MediaTypeCostMapFilter = "application/alto-costmapfilter+json" // media type for ALTO map filtering service
)
View Source
const (
	MediaTypeEndpointCost       = "application/alto-endpointcost+json"       // media type for ALTO endpoint cost service
	MediaTypeEndpointCostParams = "application/alto-endpointcostparams+json" // media type for ALTO endpoint cost service
)
View Source
const (
	MediaTypeEndpointProp       = "application/alto-endpointprop+json"       // media type for ALTO endpoint property service
	MediaTypeEndpointPropParams = "application/alto-endpointpropparams+json" // media type for ALTO endpoint property service
)
View Source
const (
	ErrSyntax              = "E_SYNTAX"
	ErrJSONFieldMissing    = "E_JSON_FIELD_MISSING"
	ErrJSONValueType       = "E_JSON_VALUE_TYPE"
	ErrInvalidCostMode     = "E_INVALID_COST_MODE"
	ErrInvalidCostMetric   = "E_INVALID_COST_METRCI"
	ErrInvalidPropertyType = "E_INVALID_PROPERTY_TYPE"
)
View Source
const (
	MediaTypeNetworkMap       = "application/alto-networkmap+json"       // media type for ALTO map service
	MediaTypeNetworkMapFilter = "application/alto-networkmapfilter+json" // media type for ALTO map filtering service
)
View Source
const (
	MediaTypeDirectory = "application/alto-directory+json" // media type for ALTO directory service
)
View Source
const (
	MediaTypeError = "application/alto-error+json" // media type for ALTO error notification
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CostMap

type CostMap struct {
	CostType   CostType            `json:"cost-type"`
	VersionTag string              `json:"map-vtag"`
	Map        map[string]DstCosts `json:"map"`
}

A CostMap reprensents a list of path costs for each pair of source/destination provider-defined identifer (PID).

func (*CostMap) MarshalJSON

func (cm *CostMap) MarshalJSON() ([]byte, error)

MarshalJSON implements the MarshalJSON method of json.Marshaler interface.

func (*CostMap) UnmarshalJSON

func (cm *CostMap) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the UnmarshalJSON method of json.Unmarshaler interface.

type CostType

type CostType struct {
	CostMetric  string `json:"cost-metric"`
	CostMode    string `json:"cost-mode"`
	Description string `json:"description,omitempty"`
}

A CostType represents a combination of cost type and cost mode.

type Data

type Data interface {
	// contains filtered or unexported methods
}

A Data represents an information resource data.

type Directory

type Directory struct {
	Meta      Meta                `json:"meta"`
	Resources []DirectoryResource `json:"resources"`
}

A Directory represents an information resource directory.

type DirectoryResource

type DirectoryResource struct {
	URI          string                 `json:"uri"`
	MediaType    string                 `json:"media-type"`
	Accepts      string                 `json:"accepts,omitempty"`
	Capabilities map[string]interface{} `json:"capabilities,omitempty"`
}

A DirectoryResource represents a list of information resources.

type DstCosts

type DstCosts map[string]float64

A DstCosts represents a set of costs for the destination provider-defined identifier (PID).

type Endpoint

type Endpoint interface {
	Network() string
	String() string
	TypedString() string
}

An Endpoint represents an endpoint address or address prefix.

func ParseEndpoint

func ParseEndpoint(typ, addr string) (Endpoint, error)

ParseEndpoint parses addr as a network endpoint identifier with address type typ. Known types are "ipv4" and "ipv6".

type EndpointAddrGroup

type EndpointAddrGroup map[string][]Endpoint

An EndpointAddrGroup represents a set of endpoints.

func (EndpointAddrGroup) MarshalJSON

func (eag EndpointAddrGroup) MarshalJSON() ([]byte, error)

MarshalJSON implements the MarshalJSON method of json.Marshaler interface.

func (EndpointAddrGroup) UnmarshalJSON

func (eag EndpointAddrGroup) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the UnmarshalJSON method of json.Unmarshaler interface.

type EndpointCostMap

type EndpointCostMap struct {
	CostType CostType                    `json:"cost-type"`
	Map      map[string]EndpointDstCosts `json:"map"`
}

An EndpointCostMap reprensents a list of endpoint cost maps.

type EndpointDstCosts

type EndpointDstCosts map[string]interface{}

An EndpointDstCosts represents a set of endpoint cost maps.

type EndpointProperty

type EndpointProperty struct {
	VersionTag string                   `json:"map-vtag"`
	Map        map[string]EndpointProps `json:"map"`
}

An EndpointProperty represents a list of endpoint properties.

type EndpointPropertyCapabilities

type EndpointPropertyCapabilities struct {
	PropTypes []string `json:"prop-types"`
}

An EndpointPropertyCapabilities reprensents a capabilities of endpoint property.

type EndpointProps

type EndpointProps map[string]interface{}

An EndpointProps represents a set of endpoint properties.

type Error

type Error struct {
	Code string `json:"code"`
}

An Error represents an error notification.

type FilteredCostMapCapabilities

type FilteredCostMapCapabilities struct {
	CostTypeNames   []string `json:"cost-type-names"`
	CostConstraints bool     `json:"cost-constraints"`
}

A FilteredCostMapCapabilities represents a capabilities for the filtered cost map.

type IPEndpoint

type IPEndpoint struct {
	IP ipaddr.Prefix
}

An IPEndpoint represents an IP address or address prefix.

func (*IPEndpoint) Network

func (ep *IPEndpoint) Network() string

Network returns the endpoint's network; "ipv4" or "ipv6".

func (*IPEndpoint) String

func (ep *IPEndpoint) String() string

func (*IPEndpoint) TypedString

func (ep *IPEndpoint) TypedString() string

TypedString returns the literal endpoint address with network prefix followed by a colon.

type MACEndpoint

type MACEndpoint net.HardwareAddr

A MACEndpoint represents a MAC address. Note that this address type is not defined in the ALTO protocol.

func (MACEndpoint) Network

func (ep MACEndpoint) Network() string

Network returns the endpoint's network; "mac-48" or "mac-64".

func (MACEndpoint) String

func (ep MACEndpoint) String() string

func (MACEndpoint) TypedString

func (ep MACEndpoint) TypedString() string

TypedString returns the literal endpoint address with network prefix followed by a colon.

type Meta

type Meta map[string]interface{}

A Meta represents a set of definitions related with the information resources.

type NetworkMap

type NetworkMap struct {
	VersionTag string                       `json:"map-vtag"`
	Map        map[string]EndpointAddrGroup `json:"map"`
}

A NetworkMap represents a list of network locations within the provider-defined identifier (PID).

func (*NetworkMap) Endpoints

func (nm *NetworkMap) Endpoints(pid, typ string) []Endpoint

Endpoints returns a list of endpoints which selected with provider-defined identifier (PID) name pid and address type typ. The zero value for string is treated as wildcard.

func (*NetworkMap) MarshalJSON

func (nm *NetworkMap) MarshalJSON() ([]byte, error)

MarshalJSON implements the MarshalJSON method of json.Marshaler interface.

func (*NetworkMap) Set

func (nm *NetworkMap) Set(pid string, ep Endpoint)

Set sets the provider-defined identifier (PID) pid to endpoiint ep. It replaces any existing endpoints.

func (*NetworkMap) UnmarshalJSON

func (nm *NetworkMap) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the UnmarshalJSON method of json.Unmarshaler interface.

type ReqEndpointCostMap

type ReqEndpointCostMap struct {
	CostType    CostType `json:"cost-type"`
	Constraints []string `json:"constraints,omitempty"`
	Endpoints   struct {
		Srcs []Endpoint `json:"srcs,omitempty"`
		Dsts []Endpoint `json:"dsts,omitempty"`
	} `json:"endpoints"`
}

A ReqEndpointCostMap represents input parameters for the filtered cost map.

type ReqEndpointProp

type ReqEndpointProp struct {
	Properties []string   `json:"properties"`
	Endpoints  []Endpoint `json:"endpoints"`
}

A ReqEndpointProp represents input parameters for the filtered endpoint properties.

type ReqFilteredCostMap

type ReqFilteredCostMap struct {
	CostType    CostType `json:"cost-type"`
	Constraints []string `json:"constraints,omitempty"`
	PIDs        struct {
		Srcs []string `json:"srcs,omitempty"`
		Dsts []string `json:"dsts,omitempty"`
	} `json:"pids,omitempty"`
}

A ReqFilteredCostMap represents input parameters for the filtered cost map.

type ReqFilteredNetworkMap

type ReqFilteredNetworkMap struct {
	PIDs      []string `json:"pids,omitempty"`
	AddrTypes []string `json:"address-types,omitempty"`
}

A ReqFilteredNetworkMap represents input parameters for the filtered network map.

type Resource

type Resource struct {
	Meta Meta `json:"meta"`
	Data Data `json:"data"`
}

A Resource represents an information resource.

func NewResource

func NewResource(typ string) *Resource

NewResource returns an information resource. Known information resource types are "networkmap" and "costmap".

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL