func (b *DemoInstance) PacketIn(dpid net.HardwareAddr, pkt *ofp10.PacketIn) { eth := pkt.Data // Ignore link discovery packet types. if eth.Ethertype == 0xa0f1 || eth.Ethertype == 0x88cc { return } b.SetHost(eth.HWSrc, pkt.InPort) if host, ok := b.Host(eth.HWDst); ok { f1 := ofp10.NewFlowMod() f1.Match.DLSrc = eth.HWSrc f1.Match.DLDst = eth.HWDst f1.AddAction(ofp10.NewActionOutput(host.port)) f1.IdleTimeout = 3 f2 := ofp10.NewFlowMod() f2.Match.DLSrc = eth.HWDst f2.Match.DLDst = eth.HWSrc f2.AddAction(ofp10.NewActionOutput(pkt.InPort)) f2.IdleTimeout = 3 if s, ok := ogo.Switch(dpid); ok { s.Send(f1) s.Send(f2) } } else { p := ofp10.NewPacketOut() p.InPort = pkt.InPort p.AddAction(ofp10.NewActionOutput(ofp10.P_ALL)) p.Data = ð if sw, ok := ogo.Switch(dpid); ok { sw.Send(p) } } }
func (o *OgoInstance) ConnectionUp(dpid net.HardwareAddr) { dropMod := ofp10.NewFlowMod() dropMod.Priority = 1 arpFmod := ofp10.NewFlowMod() arpFmod.Priority = 2 arpFmod.Match.DLType = 0x0806 // ARP Messages arpFmod.AddAction(ofp10.NewActionOutput(ofp10.P_CONTROLLER)) dscFmod := ofp10.NewFlowMod() dscFmod.Priority = 0xffff dscFmod.Match.DLType = 0xa0f1 // Link Discovery Messages dscFmod.AddAction(ofp10.NewActionOutput(ofp10.P_CONTROLLER)) if sw, ok := Switch(dpid); ok { sw.Send(ofp10.NewFeaturesRequest()) sw.Send(dropMod) sw.Send(arpFmod) sw.Send(dscFmod) sw.Send(ofp10.NewEchoRequest()) } go o.linkDiscoveryLoop(dpid) }
func (o *OgoInstance) linkDiscoveryLoop(dpid net.HardwareAddr) { for { select { case <-o.shutdown: return // Every two seconds send a link discovery packet. case <-time.After(time.Second * 2): e := eth.New() e.Ethertype = 0xa0f1 e.HWSrc = dpid[2:] linkDsc := NewLinkDiscovery() linkDsc.SrcDPID = dpid e.Data = linkDsc pkt := ofp10.NewPacketOut() pkt.Data = e pkt.AddAction(ofp10.NewActionOutput(ofp10.P_ALL)) if sw, ok := Switch(dpid); ok { sw.Send(pkt) } } } }