Skip to content

Commit 47e7dc9

Browse files
committed
adding shared host dict
1 parent 7b225c5 commit 47e7dc9

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
ogo
2+
*.go~
3+
*.prof

ogo.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"github.com/jonstout/ogo/openflow/ofp10"
77
"net"
88
"sync"
9+
"runtime"
910
)
1011

1112
// Structure to track hosts that we discover.
@@ -14,8 +15,7 @@ type Host struct {
1415
port uint16
1516
}
1617

17-
// A thread safe map to store our hosts. We are unlikely to
18-
// actually need a thread safe data structure in this demo.
18+
// A thread safe map to store our hosts.
1919
type HostMap struct {
2020
hosts map[string]Host
2121
sync.RWMutex
@@ -27,30 +27,34 @@ func NewHostMap() *HostMap {
2727
return h
2828
}
2929

30+
// Returns the host associated with mac.
3031
func (m *HostMap) Host(mac net.HardwareAddr) (h Host, ok bool) {
3132
m.RLock()
3233
defer m.RUnlock()
3334
h, ok = m.hosts[mac.String()]
3435
return
3536
}
3637

38+
// Records the host mac address and the port where mac was discovered.
3739
func (m *HostMap) SetHost(mac net.HardwareAddr, port uint16) {
3840
m.Lock()
3941
defer m.Unlock()
4042
m.hosts[mac.String()] = Host{mac, port}
4143
}
4244

45+
var hostMap HostMap
46+
4347
// Returns a new instance that implements one of the many
4448
// interfaces found in ofp/ofp10/interface.go. One
4549
// DemoInstance will be created for each switch that connects
4650
// to the network.
4751
func NewDemoInstance() interface{} {
48-
return &DemoInstance{*NewHostMap()}
52+
return &DemoInstance{&hostMap}
4953
}
5054

5155
// Acts as a simple learning switch.
5256
type DemoInstance struct {
53-
HostMap
57+
*HostMap
5458
}
5559

5660
func (b *DemoInstance) PacketIn(dpid net.HardwareAddr, pkt *ofp10.PacketIn) {
@@ -92,8 +96,9 @@ func (b *DemoInstance) PacketIn(dpid net.HardwareAddr, pkt *ofp10.PacketIn) {
9296

9397
func main() {
9498
fmt.Println("Ogo 2013")
95-
99+
runtime.GOMAXPROCS(runtime.NumCPU())
96100
ctrl := core.NewController()
101+
hostMap = *NewHostMap()
97102
ctrl.RegisterApplication(NewDemoInstance)
98103
ctrl.Listen(":6633")
99104
}

0 commit comments

Comments
 (0)