Exemplo n.º 1
0
func (of *of12Driver) handlePacketIn(in of12.PacketIn, c *ofConn) error {
	m := in.Match()
	if m.Type() == uint16(of12.PMT_STANDARD) {
		glog.Warningf("standard matches are not supported")
		return nil
	}

	var inPort uint32
	hasInPort := false

	xm, _ := of12.ToOXMatch(in.Match())
	for _, f := range xm.Fields() {
		if of12.IsOxmInPort(f) {
			xp, _ := of12.ToOxmInPort(f)
			inPort = xp.InPort()
			hasInPort = true
		}
	}

	if !hasInPort {
		glog.V(2).Infof("packet in does not have an input port")
		return nil
	}

	// Ignore packet-ins on switch specific ports.
	if inPort > uint32(of12.PP_MAX) {
		glog.V(2).Infof("ignoring packet-in on %v", inPort)
		return nil
	}

	port, ok := of.ofPorts[inPort]
	if !ok {
		return fmt.Errorf("of12Driver: port not found %v", inPort)
	}

	if glog.V(2) {
		glog.Infof("packet received: %v", in)
	}

	nomIn := nom.PacketIn{
		Node:     c.node.UID(),
		InPort:   port.UID(),
		BufferID: nom.PacketBufferID(in.BufferId()),
	}
	nomIn.Packet = nom.Packet(in.Data())
	c.ctx.Emit(nomIn)

	return nil
}
Exemplo n.º 2
0
func (d *of12Driver) nomMatch(m of12.Match) (nom.Match, error) {
	nm := nom.Match{}

	if !of12.IsOXMatch(m) {
		return nm, fmt.Errorf("of12Driver: std math is not supported")
	}

	xm, err := of12.ToOXMatch(m)
	if err != nil {
		return nm, err
	}

	for _, f := range xm.Fields() {
		if of12.IsOxmInPort(f) {
			xf, err := of12.ToOxmInPort(f)
			if err != nil {
				return nom.Match{}, err
			}

			np, ok := d.ofPorts[xf.InPort()]
			if !ok {
				return nom.Match{}, fmt.Errorf("of12Driver-Match: cannot find port %v",
					xf.InPort())
			}
			nm.AddField(nom.InPort(np.UID()))
		}
		if of12.IsOxmEthType(f) {
			xf, err := of12.ToOxmEthType(f)
			if err != nil {
				return nom.Match{}, err
			}
			nm.AddField(nom.EthType(xf.Type()))
		}

		if of12.IsOxmEthSrc(f) {
			xf, err := of12.ToOxmEthSrc(f)
			if err != nil {
				return nom.Match{}, err
			}

			nf := nom.EthSrc{}
			nf.Addr = xf.MacAddr()
			nf.Mask = nom.MaskNoneMAC
			nm.AddField(nf)
		}

		switch f.OxmField() {
		case uint8(of12.PXMT_ETH_SRC_MASKED):
			xf, err := of12.ToOxmEthSrcMasked(f)
			if err != nil {
				return nom.Match{}, err
			}

			nf := nom.EthSrc{}
			nf.Addr = xf.MacAddr()
			nf.Mask = xf.Mask()
			nm.AddField(nf)

		case uint8(of12.PXMT_ETH_DST):
			xf, err := of12.ToOxmEthDst(f)
			if err != nil {
				return nom.Match{}, err
			}

			nf := nom.EthDst{}
			nf.Addr = xf.MacAddr()
			nf.Mask = nom.MaskNoneMAC
			nm.AddField(nf)

		case uint8(of12.PXMT_ETH_DST_MASKED):
			xf, err := of12.ToOxmEthDstMasked(f)
			if err != nil {
				return nom.Match{}, err
			}

			nf := nom.EthDst{}
			nf.Addr = xf.MacAddr()
			nf.Mask = xf.Mask()
			nm.AddField(nf)

		case uint8(of12.PXMT_IP_PROTO):
			xf, err := of12.ToOxmIpProto(f)
			if err != nil {
				return nom.Match{}, err
			}

			nm.AddField(nom.IPProto(xf.Proto()))

		case uint8(of12.PXMT_IPV4_SRC):
			xf, err := of12.ToOxmIpV4Src(f)
			if err != nil {
				return nom.Match{}, err
			}

			nf := nom.IPv4Src{}
			nf.Addr = nom.IPv4Addr(xf.Addr())
			nf.Mask = nom.MaskNoneIPV4
			nm.AddField(nf)

		case uint8(of12.PXMT_IPV4_SRC_MASKED):
			xf, err := of12.ToOxmIpV4SrcMasked(f)
			if err != nil {
				return nom.Match{}, err
			}

			nf := nom.IPv4Src{}
			nf.Addr = nom.IPv4Addr(xf.Addr())
			nf.Mask = nom.IPv4Addr(xf.Mask())
			nm.AddField(nf)

		case uint8(of12.PXMT_IPV4_DST):
			xf, err := of12.ToOxmIpV4Dst(f)
			if err != nil {
				return nom.Match{}, err
			}

			nf := nom.IPv4Dst{}
			nf.Addr = nom.IPv4Addr(xf.Addr())
			nf.Mask = nom.MaskNoneIPV4
			nm.AddField(nf)

		case uint8(of12.PXMT_IPV4_DST_MASKED):
			xf, err := of12.ToOxmIpV4DstMasked(f)
			if err != nil {
				return nom.Match{}, err
			}

			nf := nom.IPv4Dst{}
			nf.Addr = nom.IPv4Addr(xf.Addr())
			nf.Mask = nom.IPv4Addr(xf.Mask())
			nm.AddField(nf)

		case uint8(of12.PXMT_IPV6_SRC):
			xf, err := of12.ToOxmIpV6Src(f)
			if err != nil {
				return nom.Match{}, err
			}

			nf := nom.IPv6Src{}
			nf.Addr = nom.IPv6Addr(xf.Addr())
			nf.Mask = nom.MaskNoneIPV6
			nm.AddField(nf)

		case uint8(of12.PXMT_IPV6_SRC_MASKED):
			xf, err := of12.ToOxmIpV6SrcMasked(f)
			if err != nil {
				return nom.Match{}, err
			}

			nf := nom.IPv6Src{}
			nf.Addr = nom.IPv6Addr(xf.Addr())
			nf.Mask = nom.IPv6Addr(xf.Mask())
			nm.AddField(nf)

		case uint8(of12.PXMT_IPV6_DST):
			xf, err := of12.ToOxmIpV6Dst(f)
			if err != nil {
				return nom.Match{}, err
			}

			nf := nom.IPv6Dst{}
			nf.Addr = nom.IPv6Addr(xf.Addr())
			nf.Mask = nom.MaskNoneIPV6
			nm.AddField(nf)

		case uint8(of12.PXMT_IPV6_DST_MASKED):
			xf, err := of12.ToOxmIpV6DstMasked(f)
			if err != nil {
				return nom.Match{}, err
			}

			nf := nom.IPv6Dst{}
			nf.Addr = nom.IPv6Addr(xf.Addr())
			nf.Mask = nom.IPv6Addr(xf.Mask())
			nm.AddField(nf)

		case uint8(of12.PXMT_TCP_SRC):
			xf, err := of12.ToOxmTcpSrc(f)
			if err != nil {
				return nom.Match{}, err
			}

			nm.AddField(nom.TransportPortSrc(xf.Port()))

		case uint8(of12.PXMT_TCP_DST):
			xf, err := of12.ToOxmTcpDst(f)
			if err != nil {
				return nom.Match{}, err
			}

			nm.AddField(nom.TransportPortDst(xf.Port()))
		}
	}

	return nm, nil
}