forked from platinasystems/vnet-platina-mk1
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
init extract from github.com/platinasystems/go
Signed-off-by: Tom Grennan <[email protected]>
- Loading branch information
0 parents
commit b746751
Showing
20 changed files
with
2,355 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
*~ | ||
*.swp | ||
*.patch | ||
*.so | ||
*.zip | ||
/vnet-platina-mk1 |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
This is a goes plugin containing Platina's Mk1 TOR driver daemon. | ||
|
||
--- | ||
|
||
*© 2015-2018 Platina Systems, Inc. All rights reserved. | ||
Use of this source code is governed by this BSD-style [LICENSE].* | ||
|
||
[LICENSE]: LICENSE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright © 2016-2018 Platina Systems, Inc. All rights reserved. | ||
// Use of this source code is governed by the GPL-2 license described in the | ||
// LICENSE file. | ||
|
||
package main | ||
|
||
import "strings" | ||
|
||
// translated counter name | ||
func xCounter(s string) string { | ||
s = counterSeparators().Replace(s) | ||
if x, found := linkStatTranslation[s]; found { | ||
s = x | ||
} | ||
return s | ||
} | ||
|
||
var cachedCounterSeparators *strings.Replacer | ||
|
||
func counterSeparators() *strings.Replacer { | ||
if cachedCounterSeparators == nil { | ||
cachedCounterSeparators = | ||
strings.NewReplacer(" ", "-", ".", "-", "_", "-") | ||
} | ||
return cachedCounterSeparators | ||
} | ||
|
||
var linkStatTranslation = map[string]string{ | ||
"port-rx-multicast-packets": "multicast", | ||
"port-rx-bytes": "rx-bytes", | ||
"port-rx-crc_error-packets": "rx-crc-errors", | ||
"port-rx-runt-packets": "rx-fifo-errors", | ||
"port-rx-undersize-packets": "rx-length-errors", | ||
"port-rx-oversize-packets": "rx-over-errors", | ||
"port-rx-packets": "rx-packets", | ||
"port-tx-total-collisions": "collisions", | ||
"port-tx-fifo-underrun-packets": "tx-aborted-errors", | ||
"port-tx-bytes": "tx-bytes", | ||
"port-tx-runt-packets": "tx-fifo-errors", | ||
"port-tx-packets": "tx-packets", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// +build dbgmk1 dbgmk1.svi | ||
|
||
package main | ||
|
||
import "github.com/platinasystems/dbg" | ||
|
||
const dbgSvi = dbg.Func |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// +build dbgmk1 dbgmk1.vnetd | ||
|
||
package main | ||
|
||
import "github.com/platinasystems/dbg" | ||
|
||
const dbgVnetd = dbg.Func |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
// Copyright © 2016-2018 Platina Systems, Inc. All rights reserved. | ||
// Use of this source code is governed by the GPL-2 license described in the | ||
// LICENSE file. | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/platinasystems/elib/parse" | ||
"github.com/platinasystems/vnet" | ||
"github.com/platinasystems/vnet/ethernet" | ||
) | ||
|
||
type event struct { | ||
vnet.Event | ||
mk1 *Mk1 | ||
in parse.Input | ||
key, value string | ||
err chan error | ||
newValue chan string | ||
isReadyEvent bool | ||
} | ||
|
||
func (e *event) String() string { | ||
return fmt.Sprintf("redis set %s = %s", e.key, e.value) | ||
} | ||
|
||
func (e *event) EventAction() { | ||
var ( | ||
hi vnet.Hi | ||
si vnet.Si | ||
bw vnet.Bandwidth | ||
enable parse.Enable | ||
media string | ||
itv float64 | ||
fec ethernet.ErrorCorrectionType | ||
addr string | ||
) | ||
if e.isReadyEvent { | ||
e.mk1.poller.pubch <- fmt.Sprint(e.key, ": ", e.value) | ||
return | ||
} | ||
e.in.Init(nil) | ||
e.in.Add(e.key, e.value) | ||
v := &e.mk1.vnet | ||
switch { | ||
case e.in.Parse("%v.speed %v", &hi, v, &bw): | ||
{ | ||
err := hi.SetSpeed(v, bw) | ||
h := v.HwIf(hi) | ||
if err == nil { | ||
e.newValue <- h.Speed().String() | ||
} | ||
e.err <- err | ||
} | ||
case e.in.Parse("%v.admin %v", &si, v, &enable): | ||
{ | ||
err := si.SetAdminUp(v, bool(enable)) | ||
es := "false" | ||
if bool(enable) { | ||
es = "true" | ||
} | ||
if err == nil { | ||
e.newValue <- es | ||
} | ||
e.err <- err | ||
} | ||
case e.in.Parse("%v.media %s", &hi, v, &media): | ||
{ | ||
err := hi.SetMedia(v, media) | ||
h := v.HwIf(hi) | ||
if err == nil { | ||
e.newValue <- h.Media() | ||
} | ||
e.err <- err | ||
} | ||
case e.in.Parse("%v.fec %v", &hi, v, &fec): | ||
{ | ||
err := ethernet.SetInterfaceErrorCorrection(v, hi, fec) | ||
if err == nil { | ||
if h, ok := v.HwIfer(hi).(ethernet.HwInterfacer); ok { | ||
e.newValue <- h.GetInterface().ErrorCorrectionType.String() | ||
} else { | ||
err = fmt.Errorf("error setting fec") | ||
} | ||
} | ||
e.err <- err | ||
} | ||
case e.in.Parse("pollInterval %f", &itv): | ||
if itv < 1 { | ||
e.err <- fmt.Errorf("pollInterval must be 1 second or longer") | ||
} else { | ||
e.mk1.poller.pollInterval = itv | ||
e.newValue <- fmt.Sprintf("%f", itv) | ||
e.err <- nil | ||
} | ||
case e.in.Parse("pollInterval.msec %f", &itv): | ||
if itv < 1 { | ||
e.err <- fmt.Errorf("pollInterval.msec must be 1 millisecond or longer") | ||
} else { | ||
e.mk1.fastPoller.pollInterval = itv | ||
e.newValue <- fmt.Sprintf("%f", itv) | ||
e.err <- nil | ||
} | ||
case e.in.Parse("kafka-broker %s", &addr): | ||
e.mk1.initProducer(addr) | ||
e.newValue <- fmt.Sprintf("%s", addr) | ||
e.err <- nil | ||
default: | ||
e.err <- fmt.Errorf("can't set %s to %v", e.key, e.value) | ||
} | ||
e.mk1.eventPool.Put(e) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Created by gen-platina-mk1-flags -- DO NOT EDIT | ||
|
||
package main | ||
|
||
const ( | ||
CopperBit uint = iota | ||
Fec74Bit | ||
Fec91Bit | ||
) | ||
|
||
var flags = []string{ | ||
"copper", | ||
"fec74", | ||
"fec91", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
// autogenerated: do not edit! | ||
// generated from gentemplate [gentemplate -d Package=main -id ifStatsPollerInterface -d VecType=ifStatsPollerInterfaceVec -d Type=ifStatsPollerInterface github.com/platinasystems/elib/vec.tmpl] | ||
|
||
// Copyright © 2016-2018 Platina Systems, Inc. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package main | ||
|
||
import ( | ||
"github.com/platinasystems/elib" | ||
) | ||
|
||
type ifStatsPollerInterfaceVec []ifStatsPollerInterface | ||
|
||
func (p *ifStatsPollerInterfaceVec) Resize(n uint) { | ||
c := uint(cap(*p)) | ||
l := uint(len(*p)) + n | ||
if l > c { | ||
c = elib.NextResizeCap(l) | ||
q := make([]ifStatsPollerInterface, l, c) | ||
copy(q, *p) | ||
*p = q | ||
} | ||
*p = (*p)[:l] | ||
} | ||
|
||
func (p *ifStatsPollerInterfaceVec) validate(new_len uint, zero ifStatsPollerInterface) *ifStatsPollerInterface { | ||
c := uint(cap(*p)) | ||
lʹ := uint(len(*p)) | ||
l := new_len | ||
if l <= c { | ||
// Need to reslice to larger length? | ||
if l > lʹ { | ||
*p = (*p)[:l] | ||
for i := lʹ; i < l; i++ { | ||
(*p)[i] = zero | ||
} | ||
} | ||
return &(*p)[l-1] | ||
} | ||
return p.validateSlowPath(zero, c, l, lʹ) | ||
} | ||
|
||
func (p *ifStatsPollerInterfaceVec) validateSlowPath(zero ifStatsPollerInterface, c, l, lʹ uint) *ifStatsPollerInterface { | ||
if l > c { | ||
cNext := elib.NextResizeCap(l) | ||
q := make([]ifStatsPollerInterface, cNext, cNext) | ||
copy(q, *p) | ||
for i := c; i < cNext; i++ { | ||
q[i] = zero | ||
} | ||
*p = q[:l] | ||
} | ||
if l > lʹ { | ||
*p = (*p)[:l] | ||
} | ||
return &(*p)[l-1] | ||
} | ||
|
||
func (p *ifStatsPollerInterfaceVec) Validate(i uint) *ifStatsPollerInterface { | ||
var zero ifStatsPollerInterface | ||
return p.validate(i+1, zero) | ||
} | ||
|
||
func (p *ifStatsPollerInterfaceVec) ValidateInit(i uint, zero ifStatsPollerInterface) *ifStatsPollerInterface { | ||
return p.validate(i+1, zero) | ||
} | ||
|
||
func (p *ifStatsPollerInterfaceVec) ValidateLen(l uint) (v *ifStatsPollerInterface) { | ||
if l > 0 { | ||
var zero ifStatsPollerInterface | ||
v = p.validate(l, zero) | ||
} | ||
return | ||
} | ||
|
||
func (p *ifStatsPollerInterfaceVec) ValidateLenInit(l uint, zero ifStatsPollerInterface) (v *ifStatsPollerInterface) { | ||
if l > 0 { | ||
v = p.validate(l, zero) | ||
} | ||
return | ||
} | ||
|
||
func (p *ifStatsPollerInterfaceVec) ResetLen() { | ||
if *p != nil { | ||
*p = (*p)[:0] | ||
} | ||
} | ||
|
||
func (p ifStatsPollerInterfaceVec) Len() uint { return uint(len(p)) } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module github.com/platinasystems/vnet-platina-mk1 | ||
|
||
require ( | ||
github.com/platinasystems/atsock v1.1.0 | ||
github.com/platinasystems/dbg v1.1.0 | ||
github.com/platinasystems/elib v1.1.0 | ||
github.com/platinasystems/fe1 v1.1.2 | ||
github.com/platinasystems/firmware-fe1a v1.1.0 | ||
github.com/platinasystems/redis v1.1.0 | ||
github.com/platinasystems/vnet v1.1.2 | ||
github.com/platinasystems/xeth v1.1.1 | ||
gopkg.in/yaml.v2 v2.2.1 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
github.com/garyburd/redigo v1.6.0 h1:0VruCpn7yAIIu7pWVClQC8wxCJEcG3nyzpMSHKi1PQc= | ||
github.com/garyburd/redigo v1.6.0/go.mod h1:NR3MbYisc3/PwhQ00EMzDiPmrwpPxAn5GI05/YaO1SY= | ||
github.com/platinasystems/accumulate v0.0.0-20181019183040-63617d15f799/go.mod h1:lc7wpU1G++0lunURQyH853Y77bwWr0hXPiLLeaxjGIY= | ||
github.com/platinasystems/accumulate v1.1.0 h1:x5mCglhHNcUJqNSAMiL3PqfWDgdZZsJ0b9CUkChqaZY= | ||
github.com/platinasystems/accumulate v1.1.0/go.mod h1:lc7wpU1G++0lunURQyH853Y77bwWr0hXPiLLeaxjGIY= | ||
github.com/platinasystems/atsock v0.0.0-20181019220955-c4cc7ae24dbf/go.mod h1:1XAb4yaMVNH9PDa7Q4sZmDqHoHSrzUfnGImUuSMpx5U= | ||
github.com/platinasystems/atsock v1.1.0 h1:+h8ismKClv31tIEOTZQhBMdDJALQhF3vDKjK2Y8H7mU= | ||
github.com/platinasystems/atsock v1.1.0/go.mod h1:1XAb4yaMVNH9PDa7Q4sZmDqHoHSrzUfnGImUuSMpx5U= | ||
github.com/platinasystems/dbg v1.1.0 h1:W2ZNmbA7q68H82xCsMc2iy+BOHpqolKgRUlQL4IaDG0= | ||
github.com/platinasystems/dbg v1.1.0/go.mod h1:sWVDySjmyMRdh9RgbbJORw6A+xIBdAmoqOXBarhswZY= | ||
github.com/platinasystems/elib v1.1.0 h1:r8z1a/Wi9SlTBo9lRWSbl9yV1n0YJ011godG7cbNNJI= | ||
github.com/platinasystems/elib v1.1.0/go.mod h1:XZy8etdf41RtMxmxEYArLL7T6QEJ5MPAIeHDqXtPCUU= | ||
github.com/platinasystems/fe1 v1.1.2 h1:bGMIQxojVonquSi2EDiQysHxdzdMXj+ksx3Y5eAfHhc= | ||
github.com/platinasystems/fe1 v1.1.2/go.mod h1:7P+3V7/e7IJyhggnBZj8Ol0TJttJwsKXupDHly2k50A= | ||
github.com/platinasystems/firmware-fe1a v1.1.0 h1:4MW5FHQLIMPDkCWnmn3FZJ8Q3yZ1oSLaPxMq1DuvL6w= | ||
github.com/platinasystems/firmware-fe1a v1.1.0/go.mod h1:F0KAFwctbk1FB557q7m6atg3aQgyHj9NmAle2KswM6E= | ||
github.com/platinasystems/i2c v1.1.0 h1:34ewZSwxMvtD5kYjJAhNtwmEsCFjiQt+o6OJ62Ni2ug= | ||
github.com/platinasystems/i2c v1.1.0/go.mod h1:Yj5hRxt+HXbW1rXv9aTtxUNZsegDjeWerUPY5BIjDVM= | ||
github.com/platinasystems/indent v1.1.0 h1:VmMAqlCw1MlWgQcygXqkLsyE0Q8atBCBX+zwWVPM8Fw= | ||
github.com/platinasystems/indent v1.1.0/go.mod h1:D3GIC7ZG6jwJtpdkiCq8/xcrP/NXInOFFr5rJPos4hA= | ||
github.com/platinasystems/log v1.1.0 h1:hjWJskNV5QC36B+fz9rIyZjMztXZeRnOCypoSALlsm4= | ||
github.com/platinasystems/log v1.1.0/go.mod h1:5Wjp9vxMfkZGWz2Ep3ghzsfarcs9MMfiE2RzKwseyKQ= | ||
github.com/platinasystems/redis v1.1.0 h1:LjQDzR4Y3oZ21a2k+JQjhw2SpdYXwhbJa80JjkLvzJc= | ||
github.com/platinasystems/redis v1.1.0/go.mod h1:lyuhkHpfn6y21/nMn7H6pbBuPk1D8pflwsatn4OIl8M= | ||
github.com/platinasystems/vnet v1.1.2 h1:vRAaLXTxbKNMbfjYMdelQONW8S4etpKUdOi3KYvPB64= | ||
github.com/platinasystems/vnet v1.1.2/go.mod h1:ys1IQV7DPZTq372+nIpfafe+2SAfLvVANSCNIrv24j8= | ||
github.com/platinasystems/xeth v1.1.1 h1:zfN6+gAuZXjJev9JkZ8layQOR/mT3bchD962Vtfs9uI= | ||
github.com/platinasystems/xeth v1.1.1/go.mod h1:MokUskjwMrKdnZ08SVlEh9dkQreCHtPPEMFA81kdahI= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE= | ||
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= |
Oops, something went wrong.