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;
}
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);
}
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();
}
}
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);
}
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";
}
}
Aggregations