Search in sources :

Example 96 with MacAddress

use of org.onlab.packet.MacAddress in project onos by opennetworkinglab.

the class SimpleFabricRouting method checkVirtualGatewayIpPacket.

/**
 * handle Packet with dstIp=virtualGatewayIpAddresses.
 * returns true(handled) or false(not for virtual gateway)
 */
private boolean checkVirtualGatewayIpPacket(InboundPacket pkt, IpAddress srcIp, IpAddress dstIp) {
    // assume valid
    Ethernet ethPkt = pkt.parsed();
    MacAddress mac = simpleFabric.vMacForIp(dstIp);
    if (mac == null || !simpleFabric.isVirtualGatewayMac(ethPkt.getDestinationMAC())) {
        /* Destination MAC should be any of virtual gateway macs */
        return false;
    } else if (dstIp.isIp4()) {
        IPv4 ipv4Packet = (IPv4) ethPkt.getPayload();
        if (ipv4Packet.getProtocol() == IPv4.PROTOCOL_ICMP) {
            ICMP icmpPacket = (ICMP) ipv4Packet.getPayload();
            if (icmpPacket.getIcmpType() == ICMP.TYPE_ECHO_REQUEST) {
                log.info("IPV4 ICMP ECHO request to virtual gateway: " + "srcIp={} dstIp={} proto={}", srcIp, dstIp, ipv4Packet.getProtocol());
                TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(pkt.receivedFrom().port()).build();
                OutboundPacket packet = new DefaultOutboundPacket(pkt.receivedFrom().deviceId(), treatment, ByteBuffer.wrap(icmpPacket.buildIcmpReply(pkt.parsed()).serialize()));
                packetService.emit(packet);
                return true;
            }
        }
        log.warn("IPV4 packet to virtual gateway dropped: " + "srcIp={} dstIp={} proto={}", srcIp, dstIp, ipv4Packet.getProtocol());
        return true;
    } else if (dstIp.isIp6()) {
        // TODO: not tested yet (2017-07-20)
        IPv6 ipv6Packet = (IPv6) ethPkt.getPayload();
        if (ipv6Packet.getNextHeader() == IPv6.PROTOCOL_ICMP6) {
            ICMP6 icmp6Packet = (ICMP6) ipv6Packet.getPayload();
            if (icmp6Packet.getIcmpType() == ICMP6.ECHO_REQUEST) {
                log.info("IPV6 ICMP6 ECHO request to virtual gateway: srcIp={} dstIp={} nextHeader={}", srcIp, dstIp, ipv6Packet.getNextHeader());
                TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(pkt.receivedFrom().port()).build();
                OutboundPacket packet = new DefaultOutboundPacket(pkt.receivedFrom().deviceId(), treatment, ByteBuffer.wrap(icmp6Packet.buildIcmp6Reply(pkt.parsed()).serialize()));
                packetService.emit(packet);
                return true;
            }
        }
        log.warn("IPV6 packet to virtual gateway dropped: srcIp={} dstIp={} nextHeader={}", srcIp, dstIp, ipv6Packet.getNextHeader());
        return true;
    }
    // unknown traffic
    return false;
}
Also used : IPv6(org.onlab.packet.IPv6) Ethernet(org.onlab.packet.Ethernet) IPv4(org.onlab.packet.IPv4) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) MacAddress(org.onlab.packet.MacAddress) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) ICMP6(org.onlab.packet.ICMP6) OutboundPacket(org.onosproject.net.packet.OutboundPacket) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) ICMP(org.onlab.packet.ICMP)

Example 97 with MacAddress

use of org.onlab.packet.MacAddress in project onos by opennetworkinglab.

the class DefaultFabricNetworkTest method createInterface.

private static Interface createInterface(int index) {
    String name = "INTF_NAME_" + index;
    ConnectPoint cp = ConnectPoint.fromString("of:0011223344556677/" + index);
    InterfaceIpAddress intfIp1 = InterfaceIpAddress.valueOf("10.10.10." + index + "/32");
    InterfaceIpAddress intfIp2 = InterfaceIpAddress.valueOf("20.20.20." + index + "/32");
    List<InterfaceIpAddress> intfIps = ImmutableList.of(intfIp1, intfIp2);
    MacAddress mac = MacAddress.valueOf("00:00:00:00:00:00");
    VlanId vlanId = VlanId.NONE;
    return new Interface(name, cp, intfIps, mac, vlanId);
}
Also used : MacAddress(org.onlab.packet.MacAddress) ConnectPoint(org.onosproject.net.ConnectPoint) InterfaceIpAddress(org.onosproject.net.host.InterfaceIpAddress) VlanId(org.onlab.packet.VlanId) Interface(org.onosproject.net.intf.Interface)

Example 98 with MacAddress

use of org.onlab.packet.MacAddress in project onos by opennetworkinglab.

the class SimpleFabricNeighbour method handleReply.

/**
 * Handles reply messages between VLAN tagged interfaces.
 *
 * @param context the message context
 * @param hostService the host service
 */
protected void handleReply(NeighbourMessageContext context, HostService hostService) {
    // Find target L2 Network, then reply to the host
    FabricNetwork fabricNetwork = simpleFabric.fabricNetwork(context.inPort(), context.vlan());
    if (fabricNetwork != null) {
        // TODO: need to check and update simpleFabric.DefaultFabricNetwork
        MacAddress mac = simpleFabric.vMacForIp(context.target());
        if (mac != null) {
            log.trace("simple fabric neightbour response message to virtual gateway; drop: {} {} target={}", context.inPort(), context.vlan(), context.target());
            context.drop();
        } else {
            // forward reply to the hosts of the dstMac
            Set<Host> hosts = hostService.getHostsByMac(context.dstMac());
            log.trace("simple fabric neightbour response message forward: {} {} target={} -> {}", context.inPort(), context.vlan(), context.target(), hosts);
            hosts.stream().map(host -> simpleFabric.hostInterface(host)).filter(Objects::nonNull).forEach(context::forward);
        }
    } else {
        // this might be happened when we remove an interface from L2 Network
        // just ignore this message
        log.warn("simple fabric neightbour response message drop for unknown fabricNetwork: {} {}", context.inPort(), context.vlan());
        context.drop();
    }
}
Also used : Host(org.onosproject.net.Host) MacAddress(org.onlab.packet.MacAddress) FabricNetwork(org.onosproject.simplefabric.api.FabricNetwork)

Example 99 with MacAddress

use of org.onlab.packet.MacAddress in project onos by opennetworkinglab.

the class VirtualHostCodec method decode.

@Override
public VirtualHost decode(ObjectNode json, CodecContext context) {
    if (json == null || !json.isObject()) {
        return null;
    }
    NetworkId nId = NetworkId.networkId(Long.parseLong(extractMember(NETWORK_ID, json)));
    MacAddress mac = MacAddress.valueOf(json.get("mac").asText());
    VlanId vlanId = VlanId.vlanId((short) json.get("vlan").asInt(VlanId.UNTAGGED));
    Set<HostLocation> locations = new HashSet<>();
    JsonNode locationNodes = json.get("locations");
    locationNodes.forEach(locationNode -> {
        PortNumber portNumber = PortNumber.portNumber(locationNode.get("port").asText());
        DeviceId deviceId = DeviceId.deviceId(locationNode.get("elementId").asText());
        locations.add(new HostLocation(deviceId, portNumber, 0));
    });
    HostId id = HostId.hostId(mac, vlanId);
    Iterator<JsonNode> ipStrings = json.get("ipAddresses").elements();
    Set<IpAddress> ips = new HashSet<>();
    while (ipStrings.hasNext()) {
        ips.add(IpAddress.valueOf(ipStrings.next().asText()));
    }
    return new DefaultVirtualHost(nId, id, mac, vlanId, locations, ips);
}
Also used : DefaultVirtualHost(org.onosproject.incubator.net.virtual.DefaultVirtualHost) DeviceId(org.onosproject.net.DeviceId) JsonNode(com.fasterxml.jackson.databind.JsonNode) NetworkId(org.onosproject.incubator.net.virtual.NetworkId) MacAddress(org.onlab.packet.MacAddress) HostId(org.onosproject.net.HostId) HostLocation(org.onosproject.net.HostLocation) IpAddress(org.onlab.packet.IpAddress) PortNumber(org.onosproject.net.PortNumber) VlanId(org.onlab.packet.VlanId) HashSet(java.util.HashSet)

Example 100 with MacAddress

use of org.onlab.packet.MacAddress in project onos by opennetworkinglab.

the class VbngResource method privateIpAddNotification.

/**
 * Create a new virtual BNG connection.
 *
 * @param privateIp IP Address for the BNG private network
 * @param mac MAC address for the host
 * @param hostName name of the host
 * @return public IP address for the new connection
 */
@POST
@Path("{privateip}/{mac}/{hostname}")
public String privateIpAddNotification(@PathParam("privateip") String privateIp, @PathParam("mac") String mac, @PathParam("hostname") String hostName) {
    log.info("Received creating vBNG request, " + "privateIp= {}, mac={}, hostName= {}", privateIp, mac, hostName);
    if (privateIp == null || mac == null || hostName == null) {
        log.info("Parameters can not be null");
        return "0";
    }
    IpAddress privateIpAddress = IpAddress.valueOf(privateIp);
    MacAddress hostMacAddress = MacAddress.valueOf(mac);
    VbngService vbngService = get(VbngService.class);
    IpAddress publicIpAddress = null;
    // Create a virtual BNG
    publicIpAddress = vbngService.createVbng(privateIpAddress, hostMacAddress, hostName);
    if (publicIpAddress != null) {
        return publicIpAddress.toString();
    } else {
        return "0";
    }
}
Also used : IpAddress(org.onlab.packet.IpAddress) MacAddress(org.onlab.packet.MacAddress) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Aggregations

MacAddress (org.onlab.packet.MacAddress)122 IpAddress (org.onlab.packet.IpAddress)52 VlanId (org.onlab.packet.VlanId)46 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)41 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)41 ConnectPoint (org.onosproject.net.ConnectPoint)33 Host (org.onosproject.net.Host)30 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)29 TrafficSelector (org.onosproject.net.flow.TrafficSelector)29 HostLocation (org.onosproject.net.HostLocation)27 HostId (org.onosproject.net.HostId)26 Ethernet (org.onlab.packet.Ethernet)24 DeviceId (org.onosproject.net.DeviceId)23 Interface (org.onosproject.net.intf.Interface)22 Set (java.util.Set)20 DhcpRecord (org.onosproject.dhcprelay.store.DhcpRecord)19 Device (org.onosproject.net.Device)19 Logger (org.slf4j.Logger)19 ProviderId (org.onosproject.net.provider.ProviderId)18 Ip4Address (org.onlab.packet.Ip4Address)16