func (b *DemoApplication) parsePacketIn(dpid string, pkt *ofp10.OfpPacketIn) { eth := pkt.Data hwSrc := eth.HWSrc.String() hwDst := eth.HWDst.String() if _, ok := b.hostMap[hwSrc]; !ok { b.hostMap[hwSrc] = pkt.InPort } if _, ok := b.hostMap[hwDst]; ok { f1 := ofp10.NewFlowMod() act1 := ofp10.NewActionOutput() act1.Port = b.hostMap[hwDst] f1.Actions = append(f1.Actions, act1) m1 := ofp10.NewMatch() m1.DLSrc = eth.HWSrc m1.DLDst = eth.HWDst f1.Match = *m1 f1.IdleTimeout = 3 f2 := ofp10.NewFlowMod() act2 := ofp10.NewActionOutput() act2.Port = b.hostMap[hwSrc] f2.Actions = append(f1.Actions, act2) m2 := ofp10.NewMatch() m2.DLSrc = eth.HWDst m2.DLDst = eth.HWSrc f2.Match = *m2 f2.IdleTimeout = 3 if s, ok := ogo.GetSwitch(dpid); ok { s.Send(f1) s.Send(f2) } } else { // Flood pktOut := ofp10.NewPacketOut() pktOut.Actions = append(pktOut.Actions, ofp10.NewActionOutput()) pktOut.Data = &pkt.Data if s, ok := ogo.GetSwitch(dpid); ok { s.Send(pktOut) } } }
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 (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 { fmt.Println(eth.HWSrc, ":", pkt.InPort, "to", eth.HWDst, ":", host.port) 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 := core.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 := core.Switch(dpid); ok { sw.Send(p) } } }
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): eth := pacit.NewEthernet() eth.Ethertype = 0xa0f1 eth.HWSrc = dpid[2:] eth.Data = NewLinkDiscovery(dpid) pkt := ofp10.NewPacketOut() pkt.Data = eth pkt.AddAction(ofp10.NewActionOutput(ofp10.P_ALL)) if sw, ok := Switch(dpid); ok { sw.Send(pkt) } } } }