Rename router.Bridge to router.InjectorConsumer

since what it does it injects and consumes packets, and something else
entirely does bridging.
This commit is contained in:
Bryan Boreham authored and Marc CARRE committed 2017-04-25 11:03:32 +01:00
1 parent 8227a3f67c
commit 334974472d
6 files changed
+40 -40

No files matched your search

+10 -10
View File
@@ -267,10 +267,10 @@ func main() {
config.Password = determinePassword(password)
overlay, bridge := createOverlay(bridgeType, bridgeConfig, config.Host, config.Port, bufSzMB, config.Password != nil)
networkConfig.Bridge = bridge
overlay, injectorConsumer := createOverlay(bridgeType, bridgeConfig, config.Host, config.Port, bufSzMB, config.Password != nil)
networkConfig.InjectorConsumer = injectorConsumer
if bridge != nil {
if injectorConsumer != nil {
if err := weavenet.DetectHairpin(weavenet.BridgeIfName, Log); err != nil {
Log.Errorf("DetectHairpin failed: %s", err)
}
@@ -491,31 +491,31 @@ func (nopPacketLogging) LogPacket(string, weave.PacketKey) {
func (nopPacketLogging) LogForwardPacket(string, weave.ForwardPacketKey) {
}
func createOverlay(bridgeType weavenet.Bridge, config weavenet.BridgeConfig, host string, port int, bufSzMB int, enableEncryption bool) (weave.NetworkOverlay, weave.Bridge) {
func createOverlay(bridgeType weavenet.Bridge, config weavenet.BridgeConfig, host string, port int, bufSzMB int, enableEncryption bool) (weave.NetworkOverlay, weave.InjectorConsumer) {
overlay := weave.NewOverlaySwitch()
var bridge weave.Bridge
var injectorConsumer weave.InjectorConsumer
var ignoreSleeve bool
switch {
case config.AWSVPC:
vpc := weave.NewAWSVPC()
overlay.Add("awsvpc", vpc)
bridge = weave.NullBridge{}
injectorConsumer = weave.NullInjectorConsumer{}
// Currently, we do not support any overlay with AWSVPC
ignoreSleeve = true
case bridgeType == nil:
bridge = weave.NullBridge{}
injectorConsumer = weave.NullInjectorConsumer{}
case bridgeType.IsFastdp():
iface, err := weavenet.EnsureInterface(config.DatapathName)
checkFatal(err)
fastdp, err := weave.NewFastDatapath(iface, port, enableEncryption)
checkFatal(err)
bridge = fastdp.Bridge()
injectorConsumer = fastdp.InjectorConsumer()
overlay.Add("fastdp", fastdp.Overlay())
case !bridgeType.IsFastdp():
iface, err := weavenet.EnsureInterface(weavenet.PcapIfName)
checkFatal(err)
bridge, err = weave.NewPcap(iface, bufSzMB*1024*1024) // bufsz flag is in MB
injectorConsumer, err = weave.NewPcap(iface, bufSzMB*1024*1024) // bufsz flag is in MB
checkFatal(err)
}
@@ -525,7 +525,7 @@ func createOverlay(bridgeType weavenet.Bridge, config weavenet.BridgeConfig, hos
overlay.SetCompatOverlay(sleeve)
}
return overlay, bridge
return overlay, injectorConsumer
}
func createAllocator(router *weave.NetworkRouter, config ipamConfig, preClaims []ipam.PreClaim, db db.DB, track tracker.LocalRangeTracker, isKnownPeer func(mesh.PeerName) bool) (*ipam.Allocator, address.CIDR) {
+10 -10
View File
@@ -209,25 +209,25 @@ func (lock *fastDatapathLock) relock() {
}
}
// Bridge bits
// InjectorConsumer bits
type fastDatapathBridge struct {
type fastDatapathInjectorConsumer struct {
*FastDatapath
}
func (fastdp *FastDatapath) Bridge() Bridge {
return fastDatapathBridge{fastdp}
func (fastdp *FastDatapath) InjectorConsumer() InjectorConsumer {
return fastDatapathInjectorConsumer{fastdp}
}
func (fastdp fastDatapathBridge) Interface() *net.Interface {
func (fastdp fastDatapathInjectorConsumer) Interface() *net.Interface {
return fastdp.iface
}
func (fastdp fastDatapathBridge) String() string {
func (fastdp fastDatapathInjectorConsumer) String() string {
return fmt.Sprint(fastdp.iface.Name, " (via ODP)")
}
func (fastdp fastDatapathBridge) Stats() map[string]int {
func (fastdp fastDatapathInjectorConsumer) Stats() map[string]int {
lock := fastdp.startLock()
defer lock.unlock()
@@ -238,12 +238,12 @@ func (fastdp fastDatapathBridge) Stats() map[string]int {
var routerBridgePortID = bridgePortID{router: true}
func (fastdp fastDatapathBridge) StartConsumingPackets(consumer BridgeConsumer) error {
func (fastdp fastDatapathInjectorConsumer) StartConsumingPackets(consumer Consumer) error {
fastdp.lock.Lock()
defer fastdp.lock.Unlock()
if fastdp.sendToPort[routerBridgePortID] != nil {
return fmt.Errorf("FastDatapath already has a BridgeConsumer")
return fmt.Errorf("FastDatapath already has a Consumer")
}
// set up delivery to the weave router port on the bridge
@@ -257,7 +257,7 @@ func (fastdp fastDatapathBridge) StartConsumingPackets(consumer BridgeConsumer)
return nil
}
func (fastdp fastDatapathBridge) InjectPacket(key PacketKey) FlowOp {
func (fastdp fastDatapathInjectorConsumer) InjectPacket(key PacketKey) FlowOp {
lock := fastdp.startLock()
defer lock.unlock()
return fastdp.bridge(routerBridgePortID, key, &lock)
@@ -5,13 +5,13 @@ import (
)
// Interface to packet handling on the local virtual bridge
type Bridge interface {
type InjectorConsumer interface {
// Inject a packet to be delivered locally
InjectPacket(PacketKey) FlowOp
// Start consuming packets from the bridge. Injected packets
// should not be included.
StartConsumingPackets(BridgeConsumer) error
StartConsumingPackets(Consumer) error
Interface() *net.Interface
String() string
@@ -19,26 +19,26 @@ type Bridge interface {
}
// A function that determines how to handle locally captured packets.
type BridgeConsumer func(PacketKey) FlowOp
type Consumer func(PacketKey) FlowOp
type NullBridge struct{}
type NullInjectorConsumer struct{}
func (NullBridge) InjectPacket(PacketKey) FlowOp {
func (NullInjectorConsumer) InjectPacket(PacketKey) FlowOp {
return nil
}
func (NullBridge) StartConsumingPackets(BridgeConsumer) error {
func (NullInjectorConsumer) StartConsumingPackets(Consumer) error {
return nil
}
func (NullBridge) Interface() *net.Interface {
func (NullInjectorConsumer) Interface() *net.Interface {
return nil
}
func (NullBridge) String() string {
func (NullInjectorConsumer) String() string {
return "no overlay bridge"
}
func (NullBridge) Stats() map[string]int {
func (NullInjectorConsumer) Stats() map[string]int {
return nil
}
+6 -6
View File
@@ -36,7 +36,7 @@ var (
type NetworkConfig struct {
BufSz int
PacketLogging PacketLogging
Bridge Bridge
InjectorConsumer InjectorConsumer
}
type PacketLogging interface {
@@ -55,8 +55,8 @@ func NewNetworkRouter(config mesh.Config, networkConfig NetworkConfig, name mesh
if overlay == nil {
overlay = NullNetworkOverlay{}
}
if networkConfig.Bridge == nil {
networkConfig.Bridge = NullBridge{}
if networkConfig.InjectorConsumer == nil {
networkConfig.InjectorConsumer = NullInjectorConsumer{}
}
router := &NetworkRouter{Router: mesh.NewRouter(config, name, nickName, overlay, common.LogLogger()), NetworkConfig: networkConfig, db: db}
@@ -73,8 +73,8 @@ func NewNetworkRouter(config mesh.Config, networkConfig NetworkConfig, name mesh
// Start listening for TCP connections, locally captured packets, and
// forwarded packets.
func (router *NetworkRouter) Start() {
log.Println("Sniffing traffic on", router.Bridge)
checkFatal(router.Bridge.StartConsumingPackets(router.handleCapturedPacket))
log.Println("Sniffing traffic on", router.InjectorConsumer)
checkFatal(router.InjectorConsumer.StartConsumingPackets(router.handleCapturedPacket))
checkFatal(router.Overlay.(NetworkOverlay).StartConsumingPackets(router.Ourself.Peer, router.Peers, router.handleForwardedPacket))
router.Router.Start()
}
@@ -152,7 +152,7 @@ func (router *NetworkRouter) handleForwardedPacket(key ForwardPacketKey) FlowOp
}
router.PacketLogging.LogForwardPacket("Injecting", key)
injectFop := router.Bridge.InjectPacket(key.PacketKey)
injectFop := router.InjectorConsumer.InjectPacket(key.PacketKey)
dstPeer := router.Macs.Lookup(dstMac)
if dstPeer == router.Ourself.Peer {
return injectFop
+2 -2
View File
@@ -23,8 +23,8 @@ type MACStatus struct {
func NewNetworkRouterStatus(router *NetworkRouter) *NetworkRouterStatus {
return &NetworkRouterStatus{
mesh.NewStatus(router.Router),
router.Bridge.String(),
router.Bridge.Stats(),
router.InjectorConsumer.String(),
router.InjectorConsumer.Stats(),
NewMACStatusSlice(router.Macs)}
}
+3 -3
View File
@@ -27,7 +27,7 @@ type Pcap struct {
readHandle *pcap.Handle
}
func NewPcap(iface *net.Interface, bufSz int) (Bridge, error) {
func NewPcap(iface *net.Interface, bufSz int) (InjectorConsumer, error) {
wh, err := newPcapHandle(iface.Name, false, 0, 0)
if err != nil {
return nil, err
@@ -36,7 +36,7 @@ func NewPcap(iface *net.Interface, bufSz int) (Bridge, error) {
return &Pcap{iface: iface, bufSz: bufSz, writeHandle: wh}, nil
}
func (p *Pcap) StartConsumingPackets(consumer BridgeConsumer) error {
func (p *Pcap) StartConsumingPackets(consumer Consumer) error {
rh, err := newPcapHandle(p.iface.Name, true, 65535, p.bufSz)
if err != nil {
return err
@@ -122,7 +122,7 @@ func (p *Pcap) Process(frame []byte, dec *EthernetDecoder, broadcast bool) {
checkWarn(p.writeHandle.WritePacketData(frame))
}
func (p *Pcap) sniff(readHandle *pcap.Handle, consumer BridgeConsumer) {
func (p *Pcap) sniff(readHandle *pcap.Handle, consumer Consumer) {
dec := NewEthernetDecoder()
for {