Search in sources :

Example 11 with NodeConnectorKey

use of org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey in project openflowplugin by opendaylight.

the class LLDPDiscoveryUtils method lldpToNodeConnectorRef.

/**
 * Returns the encoded in custom TLV for the given lldp.
 *
 * @param payload lldp payload
 * @param useExtraAuthenticatorCheck make it more secure (CVE-2015-1611 CVE-2015-1612)
 * @return nodeConnectorId - encoded in custom TLV of given lldp
 */
@SuppressWarnings("checkstyle:IllegalCatch")
public static NodeConnectorRef lldpToNodeConnectorRef(byte[] payload, boolean useExtraAuthenticatorCheck) {
    NodeConnectorRef nodeConnectorRef = null;
    if (isLLDP(payload)) {
        Ethernet ethPkt = new Ethernet();
        try {
            ethPkt.deserialize(payload, 0, payload.length * NetUtils.NUM_BITS_IN_A_BYTE);
        } catch (PacketException e) {
            LOG.warn("Failed to decode LLDP packet {}", e);
            return nodeConnectorRef;
        }
        LLDP lldp = (LLDP) ethPkt.getPayload();
        try {
            NodeId srcNodeId = null;
            NodeConnectorId srcNodeConnectorId = null;
            final LLDPTLV systemIdTLV = lldp.getSystemNameId();
            if (systemIdTLV != null) {
                String srcNodeIdString = new String(systemIdTLV.getValue(), Charset.defaultCharset());
                srcNodeId = new NodeId(srcNodeIdString);
            } else {
                throw new Exception("Node id wasn't specified via systemNameId in LLDP packet.");
            }
            final LLDPTLV nodeConnectorIdLldptlv = lldp.getCustomTLV(LLDPTLV.createPortSubTypeCustomTLVKey());
            if (nodeConnectorIdLldptlv != null) {
                srcNodeConnectorId = new NodeConnectorId(LLDPTLV.getCustomString(nodeConnectorIdLldptlv.getValue(), nodeConnectorIdLldptlv.getLength()));
            } else {
                throw new Exception("Node connector wasn't specified via Custom TLV in LLDP packet.");
            }
            if (useExtraAuthenticatorCheck) {
                boolean secure = checkExtraAuthenticator(lldp, srcNodeConnectorId);
                if (!secure) {
                    LOG.warn("SECURITY ALERT: there is probably a LLDP spoofing attack in progress.");
                    throw new Exception("Attack. LLDP packet with inconsistent extra authenticator field was received.");
                }
            }
            InstanceIdentifier<NodeConnector> srcInstanceId = InstanceIdentifier.builder(Nodes.class).child(Node.class, new NodeKey(srcNodeId)).child(NodeConnector.class, new NodeConnectorKey(srcNodeConnectorId)).toInstance();
            nodeConnectorRef = new NodeConnectorRef(srcInstanceId);
        } catch (Exception e) {
            LOG.debug("Caught exception while parsing out lldp optional and custom fields", e);
        }
    }
    return nodeConnectorRef;
}
Also used : NodeConnectorRef(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef) NodeConnector(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector) NodeConnectorId(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId) PacketException(org.opendaylight.openflowplugin.libraries.liblldp.PacketException) BufferException(org.opendaylight.openflowplugin.libraries.liblldp.BufferException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) PacketException(org.opendaylight.openflowplugin.libraries.liblldp.PacketException) Nodes(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes) LLDP(org.opendaylight.openflowplugin.libraries.liblldp.LLDP) Ethernet(org.opendaylight.openflowplugin.libraries.liblldp.Ethernet) NodeId(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId) NodeKey(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey) NodeConnectorKey(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey) LLDPTLV(org.opendaylight.openflowplugin.libraries.liblldp.LLDPTLV)

Example 12 with NodeConnectorKey

use of org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey in project openflowplugin by opendaylight.

the class PacketOutConvertorTest method buildActionForNullTransmitPacketInputAction.

private static List<Action> buildActionForNullTransmitPacketInputAction(final NodeConnectorKey nodeConKey, final short version) {
    PortNumber outPort = getPortNumber(nodeConKey, version);
    org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.OutputActionCaseBuilder outputActionCaseBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.OutputActionCaseBuilder();
    org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.output.action._case.OutputActionBuilder outputActionBuilder = new org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.output.action._case.OutputActionBuilder();
    outputActionBuilder.setPort(outPort);
    outputActionBuilder.setMaxLength(0xffff);
    outputActionCaseBuilder.setOutputAction(outputActionBuilder.build());
    ActionBuilder actionBuilder = new ActionBuilder();
    actionBuilder.setActionChoice(outputActionCaseBuilder.build());
    List<Action> actions = new ArrayList<>();
    actions.add(actionBuilder.build());
    return actions;
}
Also used : OutputActionCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCaseBuilder) Action(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action) OutputActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.output.action._case.OutputActionBuilder) ActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder) ArrayList(java.util.ArrayList) OutputActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.output.action._case.OutputActionBuilder) PortNumber(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber)

Example 13 with NodeConnectorKey

use of org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey in project openflowplugin by opendaylight.

the class PacketOutConvertorTest method toPacketOutInputAllParmTest.

/**
 * Test for PacketOutConvertor.
 */
@Test
public void toPacketOutInputAllParmTest() {
    org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder ab = new org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder();
    OutputActionBuilder output = new OutputActionBuilder();
    output.setMaxLength(OFConstants.OFPCML_NO_BUFFER);
    Uri value = new Uri(OutputPortValues.CONTROLLER.toString());
    output.setOutputNodeConnector(value);
    ab.setAction(new OutputActionCaseBuilder().setOutputAction(output.build()).build());
    ab.setOrder(0);
    ab.setKey(new ActionKey(0));
    List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action> actionList = new ArrayList<>();
    actionList.add(ab.build());
    Long bufferId = 0xfL;
    Long valueForCookie = 0xeL;
    ConnectionCookie connCook = new ConnectionCookie(valueForCookie);
    String nodeId = "node:1";
    NodeRef ref = createNodeRef(nodeId);
    String portO = "0xfffffffd";
    NodeConnectorKey egrConKey = PacketOutConvertorTest.createNodeConnKey(nodeId, portO);
    NodeConnectorRef egressConfRef = new NodeConnectorRef(createNodeConnRef(nodeId, egrConKey));
    String inPort = "2";
    NodeConnectorKey ingrConKey = PacketOutConvertorTest.createNodeConnKey(nodeId, inPort);
    NodeConnectorRef ingressConRef = new NodeConnectorRef(createNodeConnRef(nodeId, ingrConKey));
    String string = new String("sendOutputMsg_TEST");
    byte[] msg = string.getBytes();
    byte[] payload = msg;
    TransmitPacketInputBuilder transmitPacketInputBuilder = new TransmitPacketInputBuilder();
    transmitPacketInputBuilder.setAction(actionList);
    transmitPacketInputBuilder.setBufferId(bufferId);
    transmitPacketInputBuilder.setConnectionCookie(connCook);
    transmitPacketInputBuilder.setEgress(egressConfRef);
    transmitPacketInputBuilder.setIngress(ingressConRef);
    transmitPacketInputBuilder.setNode(ref);
    transmitPacketInputBuilder.setPayload(payload);
    final TransmitPacketInput transmitPacketInput = transmitPacketInputBuilder.build();
    Short version = (short) 0x04;
    byte[] datapathIdByte = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
    for (int i = 0; i < datapathIdByte.length; i++) {
        datapathIdByte[i] = 1;
    }
    BigInteger datapathId = new BigInteger(1, datapathIdByte);
    Long xid = 0xfffffL;
    PacketOutConvertorData data = new PacketOutConvertorData(version);
    data.setXid(xid);
    data.setDatapathId(datapathId);
    PacketOutInput message = convert(transmitPacketInput, data);
    Assert.assertEquals(transmitPacketInput.getBufferId(), message.getBufferId());
    Assert.assertEquals(Long.valueOf(inPort), message.getInPort().getValue());
    Assert.assertEquals(version, message.getVersion());
    Assert.assertEquals(xid, message.getXid());
    ActionConvertorData actionConvertorData = new ActionConvertorData(version);
    actionConvertorData.setDatapathId(datapathId);
    Optional<List<Action>> actionsOptional = convertorManager.convert(actionList, actionConvertorData);
    List<Action> actions = actionsOptional.orElse(Collections.emptyList());
    Assert.assertEquals(actions, message.getAction());
    Assert.assertArrayEquals(transmitPacketInput.getPayload(), message.getData());
}
Also used : OutputActionCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCaseBuilder) Action(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action) OutputActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.output.action._case.OutputActionBuilder) ActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder) TransmitPacketInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.TransmitPacketInputBuilder) ArrayList(java.util.ArrayList) Uri(org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Uri) PacketOutConvertorData(org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.PacketOutConvertorData) NodeRef(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef) OutputActionBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.output.action._case.OutputActionBuilder) ArrayList(java.util.ArrayList) List(java.util.List) NodeConnectorRef(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef) ActionConvertorData(org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.action.data.ActionConvertorData) ActionKey(org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionKey) TransmitPacketInput(org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.TransmitPacketInput) BigInteger(java.math.BigInteger) ConnectionCookie(org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.ConnectionCookie) NodeConnectorKey(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey) PacketOutInput(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInput) Test(org.junit.Test)

Example 14 with NodeConnectorKey

use of org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey in project openflowplugin by opendaylight.

the class PacketOutConvertorTest method toPacketOutInputAllParmNullTest.

/**
 * Test for {@link PacketOutConvertor} with null parameters.
 */
@Test
public void toPacketOutInputAllParmNullTest() {
    TransmitPacketInputBuilder transmitPacketInputBuilder = new TransmitPacketInputBuilder();
    Long bufferId = null;
    String nodeId = "0";
    String port = "0";
    NodeRef ref = createNodeRef(nodeId);
    NodeConnectorKey nodeConnKey = PacketOutConvertorTest.createNodeConnKey(nodeId, port);
    NodeConnectorRef egressConfRef = new NodeConnectorRef(createNodeConnRef(nodeId, nodeConnKey));
    transmitPacketInputBuilder.setBufferId(bufferId);
    transmitPacketInputBuilder.setConnectionCookie(null);
    transmitPacketInputBuilder.setAction(null);
    transmitPacketInputBuilder.setNode(ref);
    transmitPacketInputBuilder.setPayload(null);
    transmitPacketInputBuilder.setEgress(egressConfRef);
    transmitPacketInputBuilder.setIngress(null);
    TransmitPacketInput transmitPacketInput = transmitPacketInputBuilder.build();
    Short version = (short) 0x04;
    Long xid = null;
    PacketOutConvertorData data = new PacketOutConvertorData(version);
    PacketOutInput message = convert(transmitPacketInput, data);
    // FIXME : this has to be fixed along with actions changed in openflowjava
    Assert.assertEquals(buildActionForNullTransmitPacketInputAction(nodeConnKey, version), message.getAction());
    Assert.assertEquals(OFConstants.OFP_NO_BUFFER, message.getBufferId());
    Assert.assertEquals(new PortNumber(0xfffffffdL), message.getInPort());
    Assert.assertEquals(version, message.getVersion());
    Assert.assertEquals(xid, message.getXid());
    Assert.assertArrayEquals(transmitPacketInput.getPayload(), message.getData());
}
Also used : NodeRef(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef) NodeConnectorRef(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef) TransmitPacketInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.TransmitPacketInputBuilder) TransmitPacketInput(org.opendaylight.yang.gen.v1.urn.opendaylight.packet.service.rev130709.TransmitPacketInput) PortNumber(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber) PacketOutConvertorData(org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.PacketOutConvertorData) NodeConnectorKey(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey) PacketOutInput(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInput) Test(org.junit.Test)

Example 15 with NodeConnectorKey

use of org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey in project genius by opendaylight.

the class InterfaceManagerCommonUtils method getNodeConnectorFromInventoryOperDS.

public NodeConnector getNodeConnectorFromInventoryOperDS(NodeConnectorId nodeConnectorId) {
    NodeId nodeId = IfmUtil.getNodeIdFromNodeConnectorId(nodeConnectorId);
    InstanceIdentifier<NodeConnector> ncIdentifier = InstanceIdentifier.builder(Nodes.class).child(Node.class, new NodeKey(nodeId)).child(NodeConnector.class, new NodeConnectorKey(nodeConnectorId)).build();
    return IfmUtil.read(LogicalDatastoreType.OPERATIONAL, ncIdentifier, dataBroker).orNull();
}
Also used : NodeConnector(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector) FlowCapableNodeConnector(org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector) NodeId(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId) NodeKey(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey) Nodes(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes) NodeConnectorKey(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey)

Aggregations

NodeConnectorKey (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey)28 NodeConnector (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector)17 NodeConnectorId (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId)13 NodeKey (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey)12 Nodes (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes)11 FlowCapableNodeConnector (org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector)10 NodeConnectorRef (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef)10 NodeId (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId)9 NodeConnectorBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorBuilder)6 Test (org.junit.Test)5 Node (org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node)4 ArrayList (java.util.ArrayList)3 PortNumber (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber)3 FlowCapableNodeConnectorStatisticsData (org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.FlowCapableNodeConnectorStatisticsData)3 FlowCapableNodeConnectorStatisticsDataBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.FlowCapableNodeConnectorStatisticsDataBuilder)3 ReadOnlyTransaction (org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction)2 OpenflowVersion (org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion)2 PacketOutConvertorData (org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.PacketOutConvertorData)2 OutputActionCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.OutputActionCaseBuilder)2 OutputActionBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.output.action._case.OutputActionBuilder)2