device.go 2.25 KB
Newer Older
1 2 3 4 5
package hw

import (
	"fmt"

Ryan Goodfellow's avatar
Ryan Goodfellow committed
6
	"gitlab.com/mergetb/xir/lang/go/v0.2"
7 8 9 10
)

type Device struct {
	Base
11 12 13 14 15 16 17
	Procs  []Proc `json:"procs,omitempty"`
	Memory []Dimm `json:"memory,omitempty"`
	Nics   []Nic  `json:"nics,omitempty"`
	Usbs   []Usb  `json:"usbs,omitempty"`
	Ttys   []Tty  `json:"ttys,omitempty"`
	Disks  []Disk `json:"disks,omitempty"`
	GPUs   []GPU  `json:"gpus,omitempty"`
18
	PSUs   []PSU  `json:"psus,omitempty"`
19 20
}

Ryan Goodfellow's avatar
Ryan Goodfellow committed
21 22 23
func (d *Device) BaseInfo() Base { return d.Base }
func (d *Device) Show() string   { return d.Base.Model }

24 25 26 27 28 29 30 31 32
func (d *Device) Node(id string) *xir.Node {

	node := &xir.Node{
		Id: id,
		Props: xir.Props{
			"model":        d.Model,
			"manufacturer": d.Manufacturer,
			"cpu":          d.Procs,
			"memory":       d.Memory,
33
			"cost":         d.Cost,
34
			//"nics":         d.Nics,
35 36
		},
	}
Ryan Goodfellow's avatar
Ryan Goodfellow committed
37
	//XXX murder props - move to explicit model section
38
	//node.Props = make(xir.Props)
39

40 41
	kindCount := make(map[string]int)

42
	for _, nic := range d.Nics {
43 44 45 46 47 48 49

		kind := nic.GetKind()
		_, ok := kindCount[kind]
		if !ok {
			kindCount[kind] = nic.StartingIndex
		}

50 51
		for _, port := range nic.Ports {

52 53 54
			i, _ := kindCount[kind]
			kindCount[kind] = i + 1

55
			e := node.Endpoint().Set(xir.Props{
56 57
				"name":      fmt.Sprintf("%s%d", kind, i),
				"protocols": port.Protocols,
58 59
				"bandwidth": port.Capacity,
				"kind":      nic.GetKind(),
Ryan Goodfellow's avatar
Ryan Goodfellow committed
60
				"mac":       port.Mac,
61
			})
62 63 64 65 66

			if port.Breakout != "" {
				e.Props["breakout"] = port.Breakout
			}

67
			port.Endpoint = e
Ryan Goodfellow's avatar
Ryan Goodfellow committed
68
			//XXX murder props - move to explicit model section
69
			//port.Endpoint.Props = make(xir.Props)
70 71 72 73

		}
	}

Ryan Goodfellow's avatar
Ryan Goodfellow committed
74 75 76
	/* TODO: this is the right thing to do, but more support is needed in the
	*        bonsai realization engine for this to work
		for i, usb := range d.Usbs {
77

Ryan Goodfellow's avatar
Ryan Goodfellow committed
78 79 80 81
			e := node.Endpoint().Set(xir.Props{
				"name":    fmt.Sprintf("usb%d", i),
				"version": usb.Version,
			})
82

Ryan Goodfellow's avatar
Ryan Goodfellow committed
83 84
			//XXX murder props - move to explicit model section
			e.Props = make(xir.Props)
Ryan Goodfellow's avatar
Ryan Goodfellow committed
85

Ryan Goodfellow's avatar
Ryan Goodfellow committed
86
			i += 1
87

Ryan Goodfellow's avatar
Ryan Goodfellow committed
88
		}
89

Ryan Goodfellow's avatar
Ryan Goodfellow committed
90
		for i, tty := range d.Ttys {
91

Ryan Goodfellow's avatar
Ryan Goodfellow committed
92 93 94 95 96
			e := node.Endpoint().Set(xir.Props{
				"name":      fmt.Sprintf("ttyS%d", i+1),
				"protocols": tty.Port.Protocols,
			})
			tty.Port.Endpoint = e
97

Ryan Goodfellow's avatar
Ryan Goodfellow committed
98 99
			//XXX murder props - move to explicit model section
			e.Props = make(xir.Props)
Ryan Goodfellow's avatar
Ryan Goodfellow committed
100

Ryan Goodfellow's avatar
Ryan Goodfellow committed
101 102
		}
	*/
103 104 105 106

	return node

}
107 108 109 110 111 112

func (d *Device) ComponentPower() float32 {

	return 0.0

}