Search in sources :

Example 71 with IpPrefix

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

the class MappingAddressesTest method testIpv4MappingAddressMethod.

/**
 * Tests the ipv4MappingAddress method.
 */
@Test
public void testIpv4MappingAddressMethod() {
    IpPrefix ip = IpPrefix.valueOf("1.2.3.4/24");
    MappingAddress mappingAddress = MappingAddresses.ipv4MappingAddress(ip);
    IPMappingAddress ipMappingAddress = checkAndConvert(mappingAddress, MappingAddress.Type.IPV4, IPMappingAddress.class);
    assertThat(ipMappingAddress.ip(), is(equalTo(ip)));
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) Test(org.junit.Test)

Example 72 with IpPrefix

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

the class DistributedMappingStoreTest method setUp.

/**
 * Sets up the storage service test harness.
 */
@Before
public void setUp() {
    mappingStore = new DistributedMappingStore();
    mappingStore.storageService = new TestStorageService();
    mappingStore.deviceService = new InternalDeviceServiceAdapter();
    mappingStore.setDelegate(event -> {
    });
    IpPrefix ipPrefix = IpPrefix.valueOf(IP_ADDRESS);
    MappingAddress address = MappingAddresses.ipv4MappingAddress(ipPrefix);
    MappingKey key = DefaultMappingKey.builder().withAddress(address).build();
    MappingAction action = MappingActions.noAction();
    MappingTreatment treatment = DefaultMappingTreatment.builder().withAddress(address).setUnicastPriority(10).setUnicastWeight(10).build();
    MappingValue value = DefaultMappingValue.builder().withAction(action).add(treatment).build();
    device1 = new MockDevice(ProviderId.NONE, DEVICE_ID_1, Device.Type.OTHER, "foo.inc", "0", "0", "0", null, DefaultAnnotations.builder().build());
    device2 = new MockDevice(ProviderId.NONE, DEVICE_ID_2, Device.Type.OTHER, "foo.inc", "0", "0", "0", null, DefaultAnnotations.builder().build());
    Mapping originalMapping1 = DefaultMapping.builder().forDevice(DEVICE_ID_1).withId(1000L).withKey(key).withValue(value).build();
    Mapping originalMapping2 = DefaultMapping.builder().forDevice(DEVICE_ID_2).withId(2000L).withKey(key).withValue(value).build();
    mapping1 = new DefaultMappingEntry(originalMapping1);
    mapping2 = new DefaultMappingEntry(originalMapping2);
    mappingStore.activate();
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) MappingAddress(org.onosproject.mapping.addresses.MappingAddress) MappingAction(org.onosproject.mapping.actions.MappingAction) TestStorageService(org.onosproject.store.service.TestStorageService) DefaultMapping(org.onosproject.mapping.DefaultMapping) Mapping(org.onosproject.mapping.Mapping) DefaultMappingEntry(org.onosproject.mapping.DefaultMappingEntry) DefaultMappingKey(org.onosproject.mapping.DefaultMappingKey) MappingKey(org.onosproject.mapping.MappingKey) MappingTreatment(org.onosproject.mapping.MappingTreatment) DefaultMappingTreatment(org.onosproject.mapping.DefaultMappingTreatment) DefaultMappingValue(org.onosproject.mapping.DefaultMappingValue) MappingValue(org.onosproject.mapping.MappingValue) Before(org.junit.Before)

Example 73 with IpPrefix

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

the class OpenstackK8sIntegrationWebResource method installCniPtNodeRules.

/**
 * Installs CNI pass-through related flow rules for each kubernetes nodes.
 *
 * @param input JSON string
 * @return 200 ok, 400 BAD_REQUEST if the json is malformed
 * @throws IOException exception
 */
@PUT
@Path("node/pt-install")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response installCniPtNodeRules(InputStream input) throws IOException {
    log.trace("Install K8S CNI pass-through node rules");
    JsonNode json = readTreeFromStream(mapper().enable(INDENT_OUTPUT), input);
    IpAddress k8sNodeIp = IpAddress.valueOf(json.get(K8S_NODE_IP).asText());
    IpPrefix podCidr = IpPrefix.valueOf(json.get(POD_CIDR).asText());
    IpPrefix serviceCidr = IpPrefix.valueOf(json.get(SERVICE_CIDR).asText());
    IpAddress podGwIp = IpAddress.valueOf(json.get(POD_GW_IP).asText());
    String osK8sIntPortName = json.get(OS_K8S_INT_PORT_NAME).asText();
    MacAddress k8sIntOsPortMac = MacAddress.valueOf(json.get(K8S_INT_OS_PORT_MAC).asText());
    intService.installCniPtNodeRules(k8sNodeIp, podCidr, serviceCidr, podGwIp, osK8sIntPortName, k8sIntOsPortMac);
    return Response.ok().build();
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) JsonNode(com.fasterxml.jackson.databind.JsonNode) IpAddress(org.onlab.packet.IpAddress) MacAddress(org.onlab.packet.MacAddress) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) INDENT_OUTPUT(com.fasterxml.jackson.databind.SerializationFeature.INDENT_OUTPUT) PUT(javax.ws.rs.PUT)

Example 74 with IpPrefix

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

the class OpenstackK8sIntegrationWebResource method uninstallCniPtNodeRules.

/**
 * Uninstalls CNI pass-through related flow rules for each kubernetes nodes.
 *
 * @param input JSON string
 * @return 200 ok, 400 BAD_REQUEST if the json is malformed
 * @throws IOException exception
 */
@PUT
@Path("node/pt-uninstall")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response uninstallCniPtNodeRules(InputStream input) throws IOException {
    log.trace("Uninstall K8S CNI pass-through node rules");
    JsonNode json = readTreeFromStream(mapper().enable(INDENT_OUTPUT), input);
    IpAddress k8sNodeIp = IpAddress.valueOf(json.get(K8S_NODE_IP).asText());
    IpPrefix podCidr = IpPrefix.valueOf(json.get(POD_CIDR).asText());
    IpPrefix serviceCidr = IpPrefix.valueOf(json.get(SERVICE_CIDR).asText());
    IpAddress podGwIp = IpAddress.valueOf(json.get(POD_GW_IP).asText());
    String osK8sIntPortName = json.get(OS_K8S_INT_PORT_NAME).asText();
    MacAddress k8sIntOsPortMac = MacAddress.valueOf(json.get(K8S_INT_OS_PORT_MAC).asText());
    intService.uninstallCniPtNodeRules(k8sNodeIp, podCidr, serviceCidr, podGwIp, osK8sIntPortName, k8sIntOsPortMac);
    return Response.ok().build();
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) JsonNode(com.fasterxml.jackson.databind.JsonNode) IpAddress(org.onlab.packet.IpAddress) MacAddress(org.onlab.packet.MacAddress) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) INDENT_OUTPUT(com.fasterxml.jackson.databind.SerializationFeature.INDENT_OUTPUT) PUT(javax.ws.rs.PUT)

Example 75 with IpPrefix

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

the class OpenstackSwitchingDhcpHandlerTest method constructDhcpPacket.

/**
 * Constructs an Ethernet packet containing a DHCP payload.
 *
 * @param msgType DHCP message type
 * @return Ethernet packet
 */
private Ethernet constructDhcpPacket(DHCP.MsgType msgType) {
    // Ethernet frame
    Ethernet ethFrame = new Ethernet();
    ethFrame.setSourceMACAddress(CLIENT_HOST.mac());
    ethFrame.setDestinationMACAddress(MacAddress.BROADCAST);
    ethFrame.setEtherType(Ethernet.TYPE_IPV4);
    ethFrame.setVlanID((short) 2);
    // IP packet
    IPv4 ipv4Pkt = new IPv4();
    ipv4Pkt.setSourceAddress(0);
    ipv4Pkt.setDestinationAddress(BROADCAST.toInt());
    ipv4Pkt.setTtl((byte) 127);
    // UDP datagram
    UDP udpDatagram = new UDP();
    udpDatagram.setSourcePort((byte) UDP.DHCP_CLIENT_PORT);
    udpDatagram.setDestinationPort((byte) UDP.DHCP_SERVER_PORT);
    // DHCP payload
    DHCP dhcp = new DHCP();
    dhcp.setOpCode(DHCP.OPCODE_REQUEST);
    dhcp.setYourIPAddress(0);
    dhcp.setServerIPAddress(0);
    dhcp.setTransactionId(TRANSACTION_ID);
    dhcp.setClientHardwareAddress(CLIENT_HOST.mac().toBytes());
    dhcp.setHardwareType(DHCP.HWTYPE_ETHERNET);
    dhcp.setHardwareAddressLength((byte) 6);
    // DHCP options start...
    DhcpOption option = new DhcpOption();
    List<DhcpOption> optionList = new ArrayList<>();
    // DHCP message type
    option.setCode(OptionCode_MessageType.getValue());
    option.setLength((byte) 1);
    byte[] optionData = { (byte) msgType.getValue() };
    option.setData(optionData);
    optionList.add(option);
    // DHCP requested IP address
    option = new DhcpOption();
    option.setCode(OptionCode_RequestedIP.getValue());
    option.setLength((byte) 4);
    optionData = Ip4Address.valueOf(EXPECTED_IP).toOctets();
    option.setData(optionData);
    optionList.add(option);
    // DHCP domain server
    Subnet subnet = dhcpHandler.osNetworkService.subnet("subnet");
    option = new DhcpOption();
    option.setCode(OptionCode_DomainServer.getValue());
    option.setLength((byte) 8);
    ByteBuffer dnsByteBuf = ByteBuffer.allocate(8);
    dnsByteBuf.put(DEFAULT_PRIMARY_DNS.toOctets());
    dnsByteBuf.put(DEFAULT_SECONDARY_DNS.toOctets());
    option.setData(dnsByteBuf.array());
    optionList.add(option);
    // MTU
    option = new DhcpOption();
    option.setCode(DHCP_OPTION_MTU);
    option.setLength((byte) 2);
    option.setData(ByteBuffer.allocate(2).putShort(MTU).array());
    optionList.add(option);
    // classless static route
    option = new DhcpOption();
    option.setCode(OptionCode_Classless_Static_Route.getValue());
    option.setLength((byte) HOST_ROUTES_SIZE);
    ByteBuffer hostRouteByteBuf = ByteBuffer.allocate(HOST_ROUTES_SIZE);
    subnet.getHostRoutes().forEach(h -> {
        IpPrefix ipPrefix = IpPrefix.valueOf(h.getDestination());
        hostRouteByteBuf.put(bytesDestinationDescriptor(ipPrefix));
        hostRouteByteBuf.put(Ip4Address.valueOf(h.getNexthop()).toOctets());
    });
    option.setData(hostRouteByteBuf.array());
    optionList.add(option);
    // default router address setup
    option = new DhcpOption();
    option.setCode(OptionCode_RouterAddress.getValue());
    option.setLength((byte) 4);
    option.setData(Ip4Address.valueOf(subnet.getGateway()).toOctets());
    optionList.add(option);
    // DHCP options end...
    option = new DhcpOption();
    option.setCode(OptionCode_END.getValue());
    option.setLength((byte) 1);
    optionList.add(option);
    dhcp.setOptions(optionList);
    udpDatagram.setPayload(dhcp);
    ipv4Pkt.setPayload(udpDatagram);
    ethFrame.setPayload(ipv4Pkt);
    return ethFrame;
}
Also used : UDP(org.onlab.packet.UDP) IpPrefix(org.onlab.packet.IpPrefix) Ethernet(org.onlab.packet.Ethernet) IPv4(org.onlab.packet.IPv4) ArrayList(java.util.ArrayList) DhcpOption(org.onlab.packet.dhcp.DhcpOption) Subnet(org.openstack4j.model.network.Subnet) ByteBuffer(java.nio.ByteBuffer) DHCP(org.onlab.packet.DHCP)

Aggregations

IpPrefix (org.onlab.packet.IpPrefix)107 Test (org.junit.Test)37 IpAddress (org.onlab.packet.IpAddress)29 LinkedList (java.util.LinkedList)24 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)22 BgpHeader (org.onosproject.bgpio.types.BgpHeader)22 BgpPathAttributes (org.onosproject.bgpio.protocol.ver4.BgpPathAttributes)21 AsPath (org.onosproject.bgpio.types.AsPath)21 BgpValueType (org.onosproject.bgpio.types.BgpValueType)21 Origin (org.onosproject.bgpio.types.Origin)21 OriginType (org.onosproject.bgpio.types.Origin.OriginType)21 Med (org.onosproject.bgpio.types.Med)20 TrafficSelector (org.onosproject.net.flow.TrafficSelector)20 ProtocolType (org.onosproject.bgpio.protocol.linkstate.BgpNodeLSNlriVer4.ProtocolType)19 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)19 MpReachNlri (org.onosproject.bgpio.types.MpReachNlri)18 LinkStateAttributes (org.onosproject.bgpio.types.LinkStateAttributes)16 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)14 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)14 MacAddress (org.onlab.packet.MacAddress)12