forked from hswaw/hscloud
initial commit
This commit is contained in:
commit
8d7843cea4
6 changed files with 132 additions and 0 deletions
22
config.proto
Normal file
22
config.proto
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
syntax = "proto3";
|
||||||
|
|
||||||
|
message Config {
|
||||||
|
repeated Switch switch = 1;
|
||||||
|
};
|
||||||
|
|
||||||
|
message Switch {
|
||||||
|
string name = 1;
|
||||||
|
|
||||||
|
enum Connector {
|
||||||
|
CONNECTOR_INVALID = 0;
|
||||||
|
CONNECTOR_M6220 = 1;
|
||||||
|
CONNECTOR_ARISTA = 2;
|
||||||
|
};
|
||||||
|
Connector connector = 2;
|
||||||
|
string address = 3;
|
||||||
|
repeated SwitchPort managed_port = 4;
|
||||||
|
};
|
||||||
|
|
||||||
|
message SwitchPort {
|
||||||
|
string name = 1;
|
||||||
|
};
|
64
control.proto
Normal file
64
control.proto
Normal file
|
@ -0,0 +1,64 @@
|
||||||
|
syntax = "proto3";
|
||||||
|
package connector;
|
||||||
|
|
||||||
|
message GetPortsRequest {
|
||||||
|
};
|
||||||
|
|
||||||
|
message SwitchPort {
|
||||||
|
enum Speed {
|
||||||
|
SPEED_INVALID = 0;
|
||||||
|
SPEED_100M = 1;
|
||||||
|
SPEED_1G = 2;
|
||||||
|
SPEED_10G = 3;
|
||||||
|
};
|
||||||
|
string name = 1;
|
||||||
|
Speed speed = 2;
|
||||||
|
enum LinkState {
|
||||||
|
LINKSTATE_INVALID = 0;
|
||||||
|
LINKSTATE_DOWN = 1;
|
||||||
|
LINKSTATE_UP = 2;
|
||||||
|
};
|
||||||
|
LinkState link_state = 3;
|
||||||
|
enum PortMode {
|
||||||
|
PORTMODE_INVALID = 0;
|
||||||
|
// Interface is bridged to a VLAN, untagged.
|
||||||
|
PORTMODE_SWITCHPORT_UNTAGGED = 1;
|
||||||
|
// Interfaces is bridged to several tagged 802.1q VLANs.
|
||||||
|
PORTMODE_SWITCHPORT_TAGGED = 2;
|
||||||
|
// Interface is in 'generic', both tagged 802.1q and untagged mode.
|
||||||
|
PORTMODE_SWITCHPORT_GENERIC = 3;
|
||||||
|
// Interface is routed, ie routes packets from a separate L3 network
|
||||||
|
// and the Switch is the default gateway for machines in this network.
|
||||||
|
PORTMODE_ROUTED = 4;
|
||||||
|
// Interface is in a configuration state that cannot be clearly stated
|
||||||
|
// in terms of this enum, and should be reconfigured.
|
||||||
|
PORTMODE_MANGLED = 5;
|
||||||
|
};
|
||||||
|
PortMode port_mode = 4;
|
||||||
|
// For PORTMODE_SWITCHPORT_UNTAGGED and PORTMODE_SWITCHPORT_GENERIC, the
|
||||||
|
// VLAN ID that this interface is natively bridged to.
|
||||||
|
int32 vlan_native = 5;
|
||||||
|
// For PORTMODE_SWITCHPORT_TAGGED and PORTMODE_SWITCHPORT_GENERIC, the VLAN
|
||||||
|
// IDs that the interface is bridged to using 802.1q tags.
|
||||||
|
repeated int32 vlan_tagged = 6;
|
||||||
|
// For PORTMODE_ROUTED
|
||||||
|
repeated string prefixes = 7;
|
||||||
|
// Interface MTU
|
||||||
|
int32 mtu = 8;
|
||||||
|
enum SpanningTreeMode {
|
||||||
|
SPANNING_TREE_MODE_INVALID = 0;
|
||||||
|
// Send STP BPDU, on timeout switch to Forwarding.
|
||||||
|
SPANNING_TREE_MODE_AUTO_PORTFAST = 1;
|
||||||
|
// Switch to Forwarding immediately on link up.
|
||||||
|
SPANNING_TREE_MODE_PORTFAST = 2;
|
||||||
|
};
|
||||||
|
SpanningTreeMode spanning_tree_mode = 9;
|
||||||
|
};
|
||||||
|
|
||||||
|
message GetPortsResponse {
|
||||||
|
repeated SwitchPort ports = 1;
|
||||||
|
};
|
||||||
|
|
||||||
|
service SwitchControl {
|
||||||
|
rpc GetPorts(GetPortsRequest) returns (GetPortsResponse);
|
||||||
|
};
|
33
main.go
Normal file
33
main.go
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"flag"
|
||||||
|
"io/ioutil"
|
||||||
|
|
||||||
|
"github.com/golang/glog"
|
||||||
|
"github.com/golang/protobuf/proto"
|
||||||
|
|
||||||
|
confpb "code.hackerspace.pl/q3k/topo/proto/config"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
flagConfigPath string
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
flag.Set("logtostderr", "true")
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
flag.StringVar(&flagConfigPath, "config_path", "./topo.pb.text", "Text proto configuration of Topo (per config.proto)")
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
|
data, err := ioutil.ReadFile(flagConfigPath)
|
||||||
|
if err != nil {
|
||||||
|
glog.Exitf("Could not read config: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
config := confpb.Config{}
|
||||||
|
proto.UnmarshalText(string(data), &config)
|
||||||
|
glog.Infof("%+v", config)
|
||||||
|
}
|
2
proto/.gitignore
vendored
Normal file
2
proto/.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
config
|
||||||
|
control
|
4
proto/generate.go
Normal file
4
proto/generate.go
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
//go:generate protoc -I.. ../control.proto --go_out=plugins=grpc:control
|
||||||
|
//go:generate protoc -I.. ../config.proto --go_out=plugins=grpc:config
|
||||||
|
|
||||||
|
package proto
|
7
service.go
Normal file
7
service.go
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import confpb "code.hackerspace.pl/q3k/topo/proto/config"
|
||||||
|
|
||||||
|
type service struct {
|
||||||
|
config *confpb.Config
|
||||||
|
}
|
Loading…
Reference in a new issue